title: Velocity email template in /WEB-INF subfolder
body: <p>I coded service to send email. Now I have to integrate velocity freamwork and so I edit my mail-context.xml</p>
  
  <pre><code>....
  &lt;bean id="mailService" class="xxx.xxxx.xxxx.service.MailServiceImpl"&gt;
          &lt;property name="mailSender" ref="mailSender" /&gt;
          &lt;property name="simpleMailMessage" ref="customeMailMessage" /&gt;
          &lt;property name="velocityEngine" ref="velocityEngine" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="velocityEngine"
          class="org.springframework.ui.velocity.VelocityEngineFactoryBean"&gt;
          &lt;property name="velocityProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="resource.loader"&gt;webapp&lt;/prop&gt;
                  &lt;prop key="webapp.resource.loader.class"&gt;org.apache.velocity.tools.view.WebappResourceLoader&lt;/prop&gt;
                  &lt;prop key="webapp.resource.loader.path"&gt;/WEB-INF/email&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  ...
  </code></pre>
  
  <p>And I put in /WEB-INF/email my template file .vm
  This is my mail service</p>
  
  <pre><code>@Service("MailService")
  @Transactional
  public class MailServiceImpl implements MailService {
  
  
      private JavaMailSender mailSender;
  
      private VelocityEngine velocityEngine;
  
      private SimpleMailMessage simpleMailMessage;
  
      public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {
          this.simpleMailMessage = simpleMailMessage;
      }
  
      public void setMailSender(JavaMailSender mailSender) {
          this.mailSender = mailSender;
      }
  
      public void setVelocityEngine(VelocityEngine velocityEngine) {
          this.velocityEngine = velocityEngine;
      }
  .....
  public void sendEmailVelocity(final Userprofile userprofile) throws MessagingException, IOException {
  
          System.out.println("Sending mail...");
  
          MimeMessage message = mailSender.createMimeMessage();
          MimeMessageHelper helper = new MimeMessageHelper(message, true);
          Map model = new HashMap();
          model.put("user", userprofile);
          helper.setFrom("info@spidly.com");
          helper.setTo("claudio.pomo@gmail.com");
          helper.setSubject("velocity");
  
          String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "test.vm", model);
          helper.setText(text, true);
          mailSender.send(message);
          System.out.println("Mail sent!");
      }
  
  ...
  </code></pre>
  
  <p>And then the stack trace is</p>
  
  <pre><code>org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'test.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.app.VelocityEngine.mergeTemplate(VelocityEngine.java:343)
      at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:320)
      at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58)
      at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122)
      at xx.xxxxxxx.xxx.service.MailServiceImpl.sendEmailVelocity(MailServiceImpl.java:410)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      at $Proxy61.sendEmailVelocity(Unknown Source)org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'test.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.app.VelocityEngine.mergeTemplate(VelocityEngine.java:343)
      at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:320)
      at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58)
      at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122)
      at xx.xxxxx.xxxx.service.MailServiceImpl.sendEmailVelocity(MailServiceImpl.java:410)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      at $Proxy61.sendEmailVelocity(Unknown Source)
  </code></pre>
  
  <p>Any suggestion?</p>