我有以下代码使用velocityEngine
从数据库中读取模板@Bean
public VelocityEngine velocityEngine() throws VelocityException, IOException {
VelocityEngineFactory factory = new VelocityEngineFactory();
DataSourceResourceLoader ds = new DataSourceResourceLoader();
ds.setDataSource(dataSource);
Properties props = new Properties();
props.put("resource.loader", "ds");
props.put("ds.resource.loader.instance", ds);
props.put("ds.resource.loader.resource.table", "tb_velocity_template");
props.put("ds.resource.loader.resource.keycolumn", "id_template");
props.put("ds.resource.loader.resource.templatecolumn", "template_definition");
props.put("ds.resource.loader.resource.timestampcolumn", "template_timestamp");
factory.setVelocityProperties(props);
return factory.createVelocityEngine();
}
我有另一个EmailService如下: -
@服务 public class emailService {
@Autowired 私人VelocityEngine velocityEngine;
public void sendEmail(){ subject = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, “WelcomeEmail”,“Utf-8”,上下文); } }
VelocityEngine无法找到资源WelcomeEmail,尽管它存在于tb_velocity_template表中。
我不确定,为什么我在ApplicationConfiguration文件中配置的velocityengine没有在邮件服务中自动装配。