springBoot 1.5x之后不再默认支持Velocity,需要手动将Velocity给配置进来
1.添加依赖包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-velocity</artifactId> <version>1.4.1.RELEASE</version> </dependency>
2.application.yml添加相关配置信息
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
3.添加配置类
/** * velocity模板配置类 * * @author zhangzun * @create 2018-03-30 14:26 */ @ConfigurationProperties( prefix = "spring.velocity" ) @Configuration public class VelocityConfig { private Properties properties; VelocityConfig(){ properties = new Properties(); } @Bean VelocityEngine velocityEngine(){ return new VelocityEngine(properties); } public Properties getProperties() { return properties; } }