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 は次のとおりです。

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