使用freemarker出现required a single bean, but 2 were found:

启动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中


	org.springframework.boot
	spring-boot-starter-freemarker

自定义配置

@Configuration
public class FreemarkerConfig {

    @Bean
    public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
        FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
        bean.setTemplateLoaderPath("/templates/");
        return bean;
    }
}

Spring Boot已经带有FreeMarkerAutoConfiguration自动配置,不需要自己额外定义FreemarkerConfig 配置,删除配置即可。

参考链接:

https://stackoverflow.com/questions/55314413/unsatisfied-dependency-expressed-through-field-freemarkerconfig

https://segmentfault.com/a/1190000016635915

 

你可能感兴趣的:(使用freemarker出现required a single bean, but 2 were found:)