0
@Service
public class EmailService{
    VelocityEngine velocityEngine;

    @Bean
    public VelocityEngine getVelocityEngine() throws VelocityException, IOException {
        VelocityEngineFactory factory = new VelocityEngineFactory();
        Properties props = new Properties();
        props.put("resource.loader", "class");
        props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        props.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        factory.setVelocityProperties(props);
        return factory.createVelocityEngine();
    }
}

applicationContext.xml

<bean id="velocityEngine"
      class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    <property name="resourceLoaderPath" value="${velocity.resourceLoader.path}" />
</bean>

applicationContext.properties

velocity.resourceLoader.path=C:\\Users\\Dev\\Git\\MyProject\\resources\\WEB-INF\\velocity

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'voucherSummary_mail.vm'

  1. How do I get VelocityEngine without the getVelocityEngine() method?

  2. How do I make VelocityEngine get the template file from the folder that I set in applicationContext?

theAnonymous
  • 1,701
  • 2
  • 28
  • 62
  • I Believe you should use `FileResourceLoader` to get the path . like `webapp.resource.loader.path=WEB-INF/velocity` – soorapadman Feb 09 '18 at 12:23
  • Possible duplicate of [Velocity, different template paths](https://stackoverflow.com/questions/12669375/velocity-different-template-paths) – Ori Marko Feb 11 '18 at 12:49

0 Answers0