Velocity with Springboot 1.5.x

后端 未结 1 894
无人共我
无人共我 2020-12-30 13:58

With Springboot 1.4.4 I could use the VelocityEngine as bean directly. The configuration I did with the application.properties:

spring.velocity.properties.re         


        
相关标签:
1条回答
  • 2020-12-30 14:55

    I will follow Jespers advice to use FreeMarker.

    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
    

    Add the properties created the Bean:

    @Bean
    VelocityEngine velocityEngine(){
        Properties properties = new Properties();
        properties.load(this.getClass().getResourceAsStream("/application.properties"));
        return new VelocityEngine(properties);
    }
    

    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.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题