速度2不会设置属性

时间:2018-05-07 15:48:28

标签: java spring spring-mvc jboss velocity

我正在尝试将项目从Spring 3升级到Spring 5.0.5。我用这个新编写的初始化更新了速度:

minValueValidator(minValue: number): ValidatorFn {
    return (control: AbstractControl): { [key: string]: any } => {
        const valid = control.value >= minValue;
        return valid ? null : { 
            'minValue': { 
                'minimum': minValue, 
                'entered': control.value 
            } 
        };
    };
}

我正在使用以下依赖项:

private static void initVelocity() throws VelocityException, IOException{
    Properties props = new Properties();
    props.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); 
    props.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    Velocity.init( props );
}

但是出于一个奇怪的原因,当我<dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-tools</artifactId> <version>2.0</version> </dependency> 时,我得到Velocity.getProperty( "classpath.resource.loader.class");,当我尝试获取模板时,我得到null

2 个答案:

答案 0 :(得分:1)

我对Velocity并不熟悉,但我们通常会创建一个新的VelocityEngine实例。您将从特定实例而不是Velocity对象本身获取该属性。请参阅以下代码:

Properties props = new Properties()
props.put("classpath.resource.loader.class", 
          ClasspathResourceLoader.class.getName());
props.put(RuntimeConstants.RESOURCE_LOADER, "classpath");
VelocityEngine engine = new VelocityEngine(props);

现在通过

获取装载机
engine.getProperty("classpath.resource.loader.class");

答案 1 :(得分:1)

速度为removed from Spring 5deprecated in spring 4.3

  

对于Spring 5,我们正在战略性地摆脱传统的基于模板的Web视图。即使仅仅因为这个原因,我们也不会引入对任何新模板引擎的支持,而是专注于其他领域(杰克逊集成,JavaScript模板等)。 FWIW,我们将继续支持FreeMarker作为一种参考 - 在经典的Servlet MVC以及Spring的新反应式Web支持中 - 包括我们用于基于模板的视图的通用基类,其他支持类可能派生自(如Velocity)基于1.x的视图类现在就开始了。

有评论等待/请求速度2支持

  

如上所述,那里的任何利益相关者,请让Velocity团队自己为Velocity 2.0发送Spring适配器

这里有一些tips用于继续使用力度

  

删除spring.velocity.properties:

     

添加创建Bean的属性:

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