标签:ati async ann bean sele ota soft 多个 tin
使用@Enable注解4个
使用@import()将Javabean导入Spring容器中
@SpringBootApplication
@ComponentScan
@Async//异步处理。bean 类之上
//@EnableAsync使异步处理生效
//@Import({User.class,Role.class,MyConfiguration.class})//可以导入一个类,或者多个类
@Import({MyImportSelector.class})//使用importSelector的实现类进行设置,引入实现类对bean进行装配
importSelector的返回值必须是一个类的全程,该类会被Spring容器所托管
public class App {
public static void main(String[] args) {
ConfigurableApplicationContext context=SpringApplication.run(App.class, args);
System.out.println(context.getBean(User.class));
System.out.println(context.getBean(Role.class));
//System.out.println(context.getBeansOfType(Runnable.class));
context.close();
}
}
public class MyImportSelector implements ImportSelector{
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
// TODO Auto-generated method stub
return new String[] {
"com.lsq.springboot.User",
"com.lsq.springboot.Role"
};
}
}
标签:ati async ann bean sele ota soft 多个 tin
原文地址:https://www.cnblogs.com/qiqisx/p/9354100.html