我有一个FreeMarker配置:
@Configuration
public class FreeMarkerConfig {
@Bean
public FreeMarkerConfigurationFactoryBean freeMarkerConfiguration() {
FreeMarkerConfigurationFactoryBean freeMarkerConfigBean = new FreeMarkerConfigurationFactoryBean();
freeMarkerConfigBean.setTemplateLoaderPath("/templates/");
return freeMarkerConfigBean;
}
}和来自build.gradle的依赖关系
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.retry:spring-retry:1.2.5.RELEASE'
compile 'org.freemarker:freemarker:2.3.30'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'org.postgresql:postgresql'
}它可以正常工作。但是,当我在build.gradle中设置以下依赖项时:
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
我会得到一个错误:
The bean 'freeMarkerConfiguration', defined in class path resource
[org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class],
could not be registered.
A bean with that name has already been defined in class path resource
[com/lab/myservice/config/FreeMarkerConfig.class]似乎spring-data-rest也提供了配置好的FreeMarker,而且冲突也会发生。@主限定符和@限定符无效。我能做什么?
更新
尝试将exclude添加到我的主类:
@SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration.class})现在应用程序可以启动,但是FreeMarker不能工作。
发布于 2020-10-13 15:36:23
找到解决方案:
属性中设置的spring.main.allow-bean-definition-overriding=true (bean名称应该相同):
spring.freemarker.template-loader-path和使用
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'而不是spring-data-rest和org.freemarker:freemarker
https://stackoverflow.com/questions/64336394
复制相似问题