1. spring原生的xml 配置bean 现在几乎淘汰,忽略!!
2. @Component 及其衍生注解 (@Controller、@Service、@Repository)
@Component
public class Cat {
}
3. @Configuration + @Bean
@Configuration
public class AnimalConfig {
@Bean
public Dog dog() {
return new Dog();
}
}
4. 直接使用@Import
public class Bird {
}
4.1 实现 ImportSelector接口
package com.ldj.springboot.importbean.selector;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.CollectionUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
/**
* User: ldj
* Date: 2024/8/24
* Time: 23:54
* Description: No Description
*/
public class MyBeanSelector implements ImportSelector {
@Override
public String[] selectIm