结论: 使用依赖查找时,singleton会拿到相同的对象,prototype 会拿到不同的对象首先我们将User对象通过 singleton 和prototype 两种方式分别注入到容器中
结论:singleton 作用域拿到的是相同的对象,prototype 作用域拿到的仍然是不同的对象通过@Autowired方式依赖查找对象
结论:集合中会同时存在一份 singleton bean 和 prototype bean使用@Autowired直接注入map集合
结论:为了方便看到 beanName,User类实现了 BeanNameAware 接口,并定义了 初始化 和 销毁方法,具体如下:
singleton 和 prototype 都会执行初始化方法回调
但仅 singleton 会执行销毁方法回调
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |