@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;
如何在没有VelocityEngine
方法的情况下获取getVelocityEngine()
?
如何让VelocityEngine
从我在applicationContext中设置的文件夹中获取模板文件?