springBoot 整合Velocity

springBoot 1.5x之后不再默认支持Velocity,需要手动将Velocity给配置进来

1.添加依赖包


   org.springframework.boot
   spring-boot-starter-velocity
   1.4.1.RELEASE

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;
    }
}



你可能感兴趣的:(springBoot 整合Velocity)