Freemarker配置的自动装配失败 [英] Autowiring of Freemarker configuration fails

查看:97
本文介绍了Freemarker配置的自动装配失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Freemarker模板引擎发送html格式的电子邮件.我必须在几个服务中执行此操作.在一项服务中,freemarker可以正常工作,但在另一项服务中则不能.但是,与freemarker相关的代码实际上是相同的.

I trying to use Freemarker Templating Engine to send html formatted emails. I had to do this in several services. In one service, freemarker is working fine, but not in another one. But the code, relevant for freemarker, is actually the same. The autowiring of

@Autowired
private Configuration freeMarkerConfig;

不是在一项服务中工作,而是在另一项服务中工作.自动装配显示在层次结构中(例如,控制器自动装配服务,服务自动装配邮件服务,邮件服务自动装配另一个组件,自动装配freemarker ...我不知道如何解决这个问题.错误堆栈跟踪:

is not working in one service, but in another. The autowiring appears in an hierachy (e.g. controller autowires service, service autowires a mailservice, mailservice autowires another component, which autowires freemarker... I cant figure out how to solve this. The error stacktrace:

Exception encountered during context initialization - cancelling refresh attempt: 
  org.springframework.beans.factory.UnsatisfiedDependencyException: 
  Error creating bean with name 'userController': 
    Unsatisfied dependency expressed through field 'userService':
  Error creating bean with name 'userService':
    Unsatisfied dependency expressed through field 'mailService':
  Error creating bean with name 'mailServiceImpl': 
    Unsatisfied dependency expressed through field 'mailMessages': 
  Error creating bean with name 'mailMessages': 
    Unsatisfied dependency expressed through field 'freeMarkerConfig': 
    No qualifying bean of type [freemarker.template.Configuration] found for dependency [freemarker.template.Configuration]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [freemarker.template.Configuration] found for dependency [freemarker.template.Configuration]: expected at least 1 bean which qualifies as autowire candidate for this dependency. 

当我使用spring-boot 1.4.0时,不需要提供更多配置,还是我错了?因此,我没有关于freemarker的任何其他xml或java配置..我没有配置它,因为在使用Freemarker的其他服务中无需配置任何内容.

As I am using spring-boot 1.4.0, there's no need to provide more configuration, or am I wrong ? So i dont have any further xml nor java configuration for freemarker.. I didnt configured it, as there was no need to configure anything in other services, where I use freemarker.

推荐答案

由于我使用的是Spring-boot 1.4.0,因此无需提供更多功能配置,还是我错了?所以我没有任何进一步的XML或Javafreemarker的配置..我没有配置它,因为没有需要在使用freemarker的其他服务中配置任何内容.

As I am using spring-boot 1.4.0, there's no need to provide more configuration, or am I wrong ? So i dont have any further xml nor java configuration for freemarker.. I didnt configured it, as there was no need to configure anything in other services, where I use freemarker.

除非您正在使用一个启动程序项目,该项目会自动设置一个用于配置Freemarker引擎的Bean,否则您将需要创建一个.像这样:

Unless you are using a starter project that automatically sets up a bean that configures the Freemarker engine, you'll need to create one. Something like this:

@Configuration
public class MyConfiguration {
    @Bean
    freemarker.template.Configuration freeMarkerConfig() {
       return someConfigBeanInstantiatedHere;
    }
}

看起来像是一个很好的参考可以为您设置Freemarker的入门项目.

This looks like a pretty good reference for a starter project that sets up Freemarker for you.

这篇关于Freemarker配置的自动装配失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆