问题描述
使用Springboot 1.4.4,我可以直接使用VelocityEngine作为bean。
我对application.properties所做的配置:
With Springboot 1.4.4 I could use the VelocityEngine as bean directly.The configuration I did with the application.properties:
spring.velocity.properties.resource.loader=jar
spring.velocity.properties.jar.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
spring.velocity.properties.jar.runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
spring.velocity.properties.jar.runtime.log.logsystem.log4j.category=velocity
spring.velocity.cache=true
spring.velocity.charset=UTF-8
在Springboot 1.5.x中,不再有Velocity支持。
在Springboot 1.5.x中集成此配置的最佳方法是什么?
In Springboot 1.5.x there is no Velocity Support anymore.What is the best way do integrate this configuration in Springboot 1.5.x?
我已经添加了依赖项:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
并创建了Bean:
@Bean
VelocityEngine velocityEngine(){
return new VelocityEngine();
}
但缺少属性。
使用
@Autowired
ConfigurableEnvironment configurableEnvironment;
我可以解析属性,但感觉不对。
I could parse the Properties, but it feels wrong.
推荐答案
我会按照Jespers的建议使用FreeMarker。
I will follow Jespers advice to use FreeMarker.
为了回答我的问题,如果有人不能切换技术,但想转移到Springboot 1.5.x,这里是一个简单的解决方案:
属性需要更改,删除 spring.velocity.properties :
In order to answer my question, if someone cannot switch technologies but wants to move to Springboot 1.5.x, here as an easy solution:Properties need to be changed, remove spring.velocity.properties:
resource.loader=jar
jar.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
jar.runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
jar.runtime.log.logsystem.log4j.category=velocity
jar.resource.loader.cache=true
input.encoding=UTF-8
添加创建Bean的属性:
Add the properties created the Bean:
@Bean
VelocityEngine velocityEngine(){
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/application.properties"));
return new VelocityEngine(properties);
}
一个重要的缺点是,使用该解决方案,您无法在不更改Velocity引擎的情况下更改属性文件名。因此它消除了Springboot的一些灵活性。
One important drawback is, with that solution you cannot change your property file name without changing it for the Velocity engine as well. So it removes some of the flexibility of Springboot.
这篇关于Springboot 1.5.x的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!