【问题标题】:Thymeleaf - Error resolving template "email-inlineimage.html"Thymeleaf - 解析模板“email-inlineimage.html”时出错
【发布时间】:2014-08-26 07:00:18
【问题描述】:

所以,我在 Stackoverflow 中看到所有人都回答了这个问题,但对我没有任何帮助。 ( SpringMVC+Thymeleaf ,error message is : template might not exist or might not be accessible by any of the configured Template Resolvers

Error resolving template "pages", template might not exist or might not be accessible by any of the configured Template Resolvers

SpringMVC+Thymeleaf ,error message is : template might not exist or might not be accessible by any of the configured Template Resolvers

... )

这里是我的 servlet-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.2.xsd">

<!-- Basic Configurations -->
<context:annotation-config/>

<context:component-scan base-package="com.podium.italia.controller"/>
<context:component-scan base-package="com.podium.italia.service"/>
<context:component-scan base-package="com.podium.italia.model"/>
<context:component-scan base-package="com.podium.italia.repository"/>

<mvc:annotation-driven />
<mvc:default-servlet-handler />

<!-- i18n -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="WEB-INF/i18n"/>
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="useCodeAsDefaultMessage" value="true"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver">
    <property name="defaultLocale" value="en"/>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>

<!-- Email support -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="587" />
    <property name="protocol" value="smtp" />
    <property name="username" value="smmailsender@gmail.com" />
    <property name="password" value="Style@mix2014" />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.smtp.quitwait">true</prop>
        </props>
    </property>
</bean>

<!-- THYMELEAF: Template Resolver for email templates -->
<bean id="emailTemplateResolver" class="org.thymeleaf.templateresolver.ClassLoaderTemplateResolver">
    <property name="prefix" value="mail/" />
    <property name="templateMode" value="HTML5" />
    <property name="characterEncoding" value="UTF-8" />
    <property name="order" value="1" />
</bean>

<!-- THYMELEAF: Template Resolver for webapp pages   -->
<!-- (we would not need this if our app was not web) -->
<bean id="webTemplateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/" />
    <property name="templateMode" value="HTML5" />
    <property name="characterEncoding" value="UTF-8" />
    <property name="order" value="2" />
</bean>

<!-- THYMELEAF: Template Engine (Spring3-specific version) -->
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <property name="templateResolvers">
        <set>
            <ref bean="emailTemplateResolver" />
            <ref bean="webTemplateResolver" />
        </set>
    </property>
</bean>

<!-- THYMELEAF: View Resolver - implementation of Spring's ViewResolver interface -->
<!-- (we would not need this if our app was not web)                              -->
<bean id="viewResolver" class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine" />
    <property name="characterEncoding" value="UTF-8" />
</bean>

<import resource="daoContext.xml"/>

这里的电子邮件服务:

final WebContext ctx = new WebContext(request,response, request.getServletContext(), locale);

//.....

// Create the HTML body using Thymeleaf
final String htmlContent = this.templateEngine.process("email-inlineimage.html", ctx);
message.setText(htmlContent, true /* isHtml */);

还有错误:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "email-
inlineimage.html", template might not exist or might not be accessible by any of the
configured Template Resolvers
org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:924)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:898)
com.podium.italia.service.EmailService.sendMailWithInlineImages(EmailService.java:112)

【问题讨论】:

  • “email-inlineimage.html”在哪里?你能分享这个文件的路径吗?
  • 你能分享一个项目吗?
  • 告诉我们在查找资源时遇到问题,但不要告诉我们您的应用程序的结构...
  • 不,我无法共享项目,我删除了它并使用内联图像代码编写了本机 java 发送邮件,但如果有人用工作示例回答我,我会给予赏金,我会接受你的回答

标签: java spring-mvc thymeleaf


【解决方案1】:

我无法在您的servlet-context.xml 中发现错误,因此问题必须隐藏在其他地方(您确定您的类路径上的模板文件正好位于mail/email-inlineimage.html 吗?)。我提供了整个项目的工作示例(因为将所有内容粘贴到此处的代码示例有点过头了),您可以将其导入STS 并运行。

Spring Thymeleaf Mailing

【讨论】:

    猜你喜欢
    • 2016-12-21
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    相关资源
    最近更新 更多