Springboot 1 的速度5.x
Velocity with 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?
我已经添加了依赖:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
并创建了 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的灵活性。
使用 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?
我已经添加了依赖:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
并创建了 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的灵活性。