ImportSelector
1).定义Bean对象
@Data
public class User {
private String userName;
private Integer age;
}
2).定义配置类Configuration
//定义一个Configuration,这里并没有使用spring注解,spring扫描的时候并不会装载该类
public class UserConfiguration {
@Bean
public User getUser(){
User user = new User();
user.setUserName("大傻子");
user.setAge(21);
return user;
}
}
3).定义ImportSelector
public class UserImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
//获取配置类的名称
//自动找到类,然后把类放入容器里面,进而帮助我们创建出对象
r