import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
//自定义需要返回导入的数组
public class MyImportSeletor implements ImportSelector {
//返回值就是导入到容器中组件的全类名
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
// TODO Auto-generated method stub
//不要返回null值,否则会报空指针异常
return new String[]{"com.ceshi.bean.Black"};
}
}
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import com.ceshi.bean.Color;
import com.ceshi.bean.MyImportSeletor;
import com.ceshi.bean.PersonBean;
import com.ceshi.demo.MyFilterType;
//配置类==配置文件(xml)
@Configuration //告诉Spring这个一个配制类
/**
* @import[快速给容器导入组件]
* 1】、@Import({Color.class}) :导入容器中的组件,容器中默认就会自动注册这个组件,id默认为类的全类名
* 2】、ImportSelector : 返回需要导入的组件的全类名数组
*/
@Import({Color.class,MyImportSeletor.class})
public class BeanConfig4 {
@Bean("person")
public PersonBean personBean2(){
return new PersonBean("lishi","20");
}
}