VelocityEngine - 如何正确获取它并找不到.vm文件

时间:2018-02-09 07:50:08

标签: java spring velocity

@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:无法找到资源&#39; voucherSummary_mail.vm&#39;

  1. 如何在没有VelocityEngine方法的情况下获取getVelocityEngine()

  2. 如何让VelocityEngine从我在applicationContext中设置的文件夹中获取模板文件?

0 个答案:

没有答案