2014-07-05 49 views
3

所以,我看到所有在Stackoverflow中回答這個問題,但對我沒有任何幫助。 ( SpringMVC+Thymeleaf ,error message is : template might not exist or might not be accessible by any of the configured Template ResolversThymeleaf - 解決模板錯誤「email-inlineimage.html」

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="[email protected]" /> 
    <property name="password" value="[email protected]" /> 
    <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"/> 

這裏emailService:

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) 
+0

「email-inlineimage.html」在哪裏存在?你能分享這個文件的路徑嗎? – ndrone

+0

你可以分享一個項目嗎? – geoand

+0

告訴我們有一個問題,找到一個資源,但不告訴我們你的應用程序的結構... – JamesB

回答

1

我可以在你的servlet-context.xml所以問題不點誤差必須被埋葬在其他地方(你確定你有正好在類路徑上的模板文件mail/email-inlineimage.html?)。我提供了整個項目的工作示例(因爲將所有內容都粘貼到代碼示例中是過分的),您可以將其導入到STS並運行。

Spring Thymeleaf Mailing