我试图使用Freemarker模板引擎发送HTML格式的电子邮件。 我不得不在多项服务中这样做。 在一项服务中,freemarker工作正常,但不在另一项服务中。 但与Freemarker相关的代码实际上是相同的。 的Freemarker配置自动装配失败
@Autowired
private Configuration freeMarkerConfig;
自动装配不服务于一体的工作,但在另一个。 自动装配出现在一个层次结构(例如控制器autowires服务,服务autowires一个MailService的,MailService的autowires另一个组件,该组件的freemarker autowires ... 我不能找出如何解决这个 错误堆栈跟踪:
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,所以没有必要提供更多的配置,或者我错了吗?所以我没有任何进一步的xml和java配置freemarker ..我没有配置它,因为没有必要配置任何其他服务,我使用freemarker。
这对我很有用,非常感谢。但是仍然会感兴趣,为什么freemarker可以在另一个项目中工作,而没有配置。另外freemarker.templates.Configuration构造函数似乎不推荐使用。有没有更新的配置Freemarker的方法? – lunatikz
也适用于我... –