2

我正在使用 spring mvc 以速度 1.7 jar 发送电子邮件内容。这是我的bean配置。

`<bean id="velocityEngine" 
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    <property name="velocityProperties">
         <value>
          resource.loader=class
          class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
         </value>
    </property>
</bean>
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
 <property name="resourceLoaderPath" value="/WEB-INF/classes/velocity/"/>
 </bean>


 <bean id="viewResolver"  class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
 <property name="cache" value="true"/>
 <property name="prefix" value=""/>
 <property name="suffix" value=".vm"/>
 </bean>

我的 serviceImpl 如下:`public class SendEmailContentImpl implements SendEmailContentService{

private JavaMailSenderImpl mailSender;
private VelocityEngine velocityEngine;
 // private VelocityEngine velocityEngine = new VelocityEngine();

   @Override
   public void sendConfirmationEmail(final User user) {     
       try{
     MimeMessagePreparator preparator = new MimeMessagePreparator() {


         public void prepare(MimeMessage mimeMessage) throws Exception {

                System.out.println("In Service impl");
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setTo("To address");
                message.setFrom("fromm address"); // could be parameterized...
                message.setSubject("Notification");

                Map model = new HashMap();
                model.put("user", user);

                String text=VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,"sendEmailTemplate.vm", model);
                System.out.println("TEXT=="+text);
                message.setText(text, true);
                        }
                    };    

      mailSender=new org.springframework.mail.javamail.JavaMailSenderImpl();
      mailSender.setHost("smtp.gmail.com");

      Properties javaMailProperties=new Properties();
      javaMailProperties.setProperty("mail.smtp.starttls.enable", "true");


      mailSender.setJavaMailProperties(javaMailProperties);
      mailSender.setUsername("mygmailAddress");
      mailSender.setPassword("*******");

      System.out.println(mailSender);
     this.mailSender.send(preparator);
     System.out.println("Email Sent-Impl");
         }catch(MailException e)
         {
      e.printStackTrace();
         }
         }

` 我将 .vm 文件放置为 /WEB-INF/classes/velocity/sendEmailContent.vm。

我总是收到这个错误,说找不到资源。我在这里打印整个 stackTrace

org.springframework.mail.MailPreparationException: Could not prepare mail; nested exception is org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'WEB-INF/classes/velocity/sendEmailTemplate.vm'
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:367)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:344)
at info.aikya.service.sendEmailContent.SendEmailContentImpl.sendConfirmationEmail(SendEmailContentImpl.java:87)
at info.aikya.controller.SendEmailContentController.handleRequest(SendEmailContentController.java:48)
at info.aikya.controller.SendEmailContentController$$FastClassByCGLIB$$a0827eb0.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at info.aikya.controller.SendEmailContentController$$EnhancerByCGLIB$$542fadd4.handleRequest(<generated>)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:679)Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'WEB-INF/classes/velocity/sendEmailTemplate.vm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373)
at info.aikya.service.sendEmailContent.SendEmailContentImpl$1.prepare(SendEmailContentImpl.java:55)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:352)
... 32 more

请帮我看看我应该把我的 .vm 文件放在哪里?

4

0 回答 0