spring 版本:4.3.2.RELEASE
代码如下:
@ComponentScan
public class App {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(App.class);
context.refresh();
context.close();
}
}
@Order(2)
@Configuration
public class MyConfig1 {
@Bean
public Runnable createRunnable1(){
System.out.println("======1=====");
return () -> {};
}
}
@Order(1)
@Configuration
public class MyConfig2 {
@Bean
public Runnable createRunnable2(){
System.out.println("======2=====");
return () -> {};
}
}
执行main方法之后,始终都是先输出1,然后输出2。
请问,自动扫描之后,@Order为啥不生效
我也遇到过这个问题,而且使用@AfterAutoConfiguration也没用。
我是在 MyConfig1 里注入了 MyConfig2 后解决的
找到这篇文章:https://blog.frankel.ch/desig... 看上去似乎可行