spring boot:2.0.3
jdk:1.8
自动创建bean即大家常见的这样的注解。 @EnableWebMvc @EnableCacheing 等等
具体实现方式有3种。
方式1:使用@Import + @Configuration 组合
@Configuration
public class HelloConfiguration {
@Bean
public HelloBean helloBean() {
return new HelloBean();
}
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(HelloConfiguration.class)
public @interface EnableHelloWithConfiguration {
}
方式2:使用@Import + ImportSelect实现类 的组合
public class HelloSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
ObjectMapper om = new ObjectMapper();
try {
System.out.println("importingClassMetadata..." + om.writeValueAsSt