Spring boot 自动连线速度发动机不工作
下面是使用velocityEngine从数据库读取模板的代码Spring boot 自动连线速度发动机不工作,spring-boot,velocity,autowired,Spring Boot,Velocity,Autowired,下面是使用velocityEngine从数据库读取模板的代码 @Bean public VelocityEngine velocityEngine() throws VelocityException, IOException { VelocityEngineFactory factory = new VelocityEngineFactory(); DataSourceResourceLoader ds = new DataSourceResourceLoader(); ds.se
@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();
}
我有另一个电子邮件服务,如下所示:-
@服务
公共类电子邮件服务{
@自动连线
私人VelocityEngine VelocityEngine
public void sendmail(){
主题=
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
“欢迎电子邮件”、“Utf-8”、上下文);
}
}
VelocityEngine无法找到资源WelcomeEmail,即使它存在于tb_velocity_模板表中
我不确定,为什么我在ApplicationConfiguration文件中配置的velocityengine没有在mailservice中自动连接。如何在应用程序上下文文件中配置velocityengine对象?@EnableAutoConfiguration(exclude={VelocityAutoConfiguration.class})将其添加到我的ApplicationConfiguration文件后,velocity引擎现在能够从数据库中读取模板。干杯:)