Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在不使用@Primary Spring Boot的情况下指定默认@Bean_Java_Spring_Spring Boot - Fatal编程技术网

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