启动springboot
Description:
Field freemarkerConfiguration in com.happyghost.springmaildemo.service.MailServiceImpl required a single bean, but 2 were found:
- getFreeMarkerConfiguration: defined by method 'getFreeMarkerConfiguration' in class path resource [com/happyghost/springmaildemo/config/FreemarkerConfig.class]
- freeMarkerConfiguration: defined by method 'freeMarkerConfiguration' in class path resource [org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class]
Action:Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
使用pom.xml中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
自定义配置
@Configuration
public class FreemarkerConfig {
@Bean
public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
bean.setTemplateLoaderPath("/templates/");
return bean;
}
}
Spring Boot已经带有FreeMarkerAutoConfiguration自动配置,不需要自己额外定义FreemarkerConfig 配置,删除配置即可。
参考链接:
https://segmentfault.com/a/1190000016635915