Java 在不使用@Primary Spring Boot的情况下指定默认@Bean
有这样一个豆子:Java 在不使用@Primary Spring Boot的情况下指定默认@Bean,java,spring,spring-boot,Java,Spring,Spring Boot,有这样一个豆子: @Bean TemplateEngine myTemplateEngine() {...} 但是Spring boot也有一个定义在中的TemplateEngine bean: org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration$ThymeleafDefaultConfiguration.class 当我使用autowire TemplateEngine时 字段需要一个bean
@Bean
TemplateEngine myTemplateEngine() {...}
但是Spring boot也有一个定义在中的TemplateEngine bean:
org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration$ThymeleafDefaultConfiguration.class
当我使用autowire TemplateEngine时
字段需要一个bean,但找到了2个
我希望springbootbean是默认的,并且只有在明确指定的情况下才使用我的bean,所以我不能使用@Primary注释,因为我没有访问该bean定义的权限
另外,我也希望避免使用xml配置。尝试将bean定义为
@Bean
@ConditionalOnMissingBean(TemplateEngine .class)
TemplateEngine myTemplateEngine() {...}
您需要使用onconditional注释,以确保在springbootsdefault失败时选择bean