gpt4 book ai didi

java - spring freemarker ConversionNotSupportedException

转载 作者:行者123 更新时间:2023-12-01 15:49:14 24 4
gpt4 key购买 nike

我正在尝试在 JBoss 5.1 Web 应用程序服务器上的 Web 应用程序中使用 Freemarker 作为模板电子邮件。

邮件上下文-xml:

<bean id="freemarkerConfiguration"
class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="/WEB-INF/templates" />
</bean>


<bean id="registrationMailService" class="com.epam.darts.webapp.utils.RegistrationMailService">
<property name="configuration" ref="freemarkerConfiguration" />
<property name="mailSender" ref="mailSender" />
</bean>

RegistrationMailService.java:

public class RegistrationMailService {

private JavaMailSender mailSender;
private Configuration configuration;

public void sendConfirmationEmail(final User user) {
MimeMessage message = this.mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
try {
helper.setFrom(user.getLogin());

helper.setTo(user.getLogin());
helper.setSubject(user.getLogin());

Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);

String sendText = FreeMarkerTemplateUtils.processTemplateIntoString(
this.configuration.getTemplate("regisstration_mail.html"), model);
helper.setText(sendText, true);
this.mailSender.send(helper.getMimeMessage());
}
catch(MessagingException e) {
e.printStackTrace();
}
}

public void setMailSender(final JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public void setConfiguration(final Configuration configuration) {
this.configuration = configuration;
}
}

freemarker 的 Maven 依赖性:

    <dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.9</version>
</dependency>

第一次用,效果很好。但是如果我尝试重新部署我的应用程序(mvn clean package jboss:hard-deploy),我会收到错误

 18:17:46,839 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationMailService' defined in
ServletContext resource [/WEB-INF/spring/spring-mail.xml]: Initialization of bean failed; nested exception is org.springfram
ework.beans.ConversionNotSupportedException: Failed to convert property value of type 'freemarker.template.Configuration' to
required type 'freemarker.template.Configuration' for property 'configuration'; nested exception is java.lang.IllegalStateE
xception: Cannot convert value of type [freemarker.template.Configuration] to required type [freemarker.template.Configurati
on] for property 'configuration': no matching editors or conversion strategy found

可能问题出在类加载器中,但我不知道如何修复它。

最佳答案

您的类路径中似乎有两份 freemarker 的 JAR 文件副本。您需要找到它们,并将范围缩小到一个。

关于java - spring freemarker ConversionNotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6456890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com