Springboot 1.5.x的速度
使用Springboot 1.4.4,我可以直接使用VelocityEngine作为bean。 我使用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中集成此配置的最佳方法是什么?
我已经添加了依赖项:
org.apache.velocity velocity 1.7
并创建了Bean:
@Bean VelocityEngine velocityEngine(){ return new VelocityEngine(); }
但是属性遗失了。
同
@Autowired ConfigurableEnvironment configurableEnvironment;
我可以解析属性,但感觉不对。
我将按照Jespers的建议使用FreeMarker。
为了回答我的问题,如果有人不能切换技术但想转移到Springboot 1.5.x,这里作为一个简单的解决方案:需要更改属性,删除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的属性:
@Bean VelocityEngine velocityEngine(){ Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/application.properties")); return new VelocityEngine(properties); }
一个重要的缺点是,使用该解决方案,您无法在不更改Velocity引擎的情况下更改属性文件名。 因此它消除了Springboot的一些灵活性。