速度 2 不会设置 属性
Velocity 2 won't set property
我正在尝试将项目从 Spring 3 升级到 Spring 5.0.5。我用我写的这个新初始化更新了速度:
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
,而当我尝试获取一个模板时,我得到了一个 NullPointerException
。
我不太精通 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");
速度为 removed from Spring 5 ( )
For Spring 5, we are strategically moving away from traditional template-based web views in general. Even just for that reason alone, we are not going to introduce support for any new template engine generations but rather focus on other areas (Jackson integration, JavaScript templates, etc). FWIW, we are going to keep supporting FreeMarker as a sort of reference - in classic Servlet MVC as well as Spring's new reactive web support -, including our generic base classes for template-based views which other support classes may derive from (like the Velocity 1.x based view classes do right now).
wait/request velocity 2 支持有评论
As mentioned above, any stakeholders there, please ask the Velocity team to ship Spring adapters for Velocity 2.0 themselves
还有一些 可以继续使用 velocity
remove spring.velocity.properties:
Add the properties created the Bean:
@Bean
VelocityEngine velocityEngine(){
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/application.properties"));
return new VelocityEngine(properties);
}
我正在尝试将项目从 Spring 3 升级到 Spring 5.0.5。我用我写的这个新初始化更新了速度:
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
,而当我尝试获取一个模板时,我得到了一个 NullPointerException
。
我不太精通 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");
速度为 removed from Spring 5 (
For Spring 5, we are strategically moving away from traditional template-based web views in general. Even just for that reason alone, we are not going to introduce support for any new template engine generations but rather focus on other areas (Jackson integration, JavaScript templates, etc). FWIW, we are going to keep supporting FreeMarker as a sort of reference - in classic Servlet MVC as well as Spring's new reactive web support -, including our generic base classes for template-based views which other support classes may derive from (like the Velocity 1.x based view classes do right now).
wait/request velocity 2 支持有评论
As mentioned above, any stakeholders there, please ask the Velocity team to ship Spring adapters for Velocity 2.0 themselves
还有一些
remove spring.velocity.properties:
Add the properties created the Bean:
@Bean VelocityEngine velocityEngine(){ Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/application.properties")); return new VelocityEngine(properties); }