摘要: 如果Bean A 在创建前需要先创建BeanB此时就可以使用DependsOn注解 @Configuration public class MyConfig { @Bean @DependsOn("apple") public Student student(){ System.out.printl 阅读全文
posted @ 2020-08-03 19:03 yangxiaohui227 阅读(3231) 评论(0) 推荐(0)
摘要: 背景,如果有一个类C,需要用到类B,如果使用@Autowired注解注入B,那么B每次调用都是同一个对象,即使B不是单例的,现在我希望每次调用B都是不一样的,那么实现方案有2个: 方案A : 每次从容器中获取B: @Component @Scope(scopeName= ConfigurableBe 阅读全文
posted @ 2020-08-03 18:55 yangxiaohui227 阅读(2389) 评论(0) 推荐(1)
摘要: 1.下面结果执行后会报空指针吗? public class A { public static int num=2; } public class App { public static void main( String[] args ) { A a=null; System.out.printl 阅读全文
posted @ 2020-08-03 10:22 yangxiaohui227 阅读(116) 评论(0) 推荐(0)