我已经将我的java web项目从spring 1.5.22升级到2.6.6。在升级过程中,速度包甚至不受欢迎,它被删除了。我知道建议切换到FreeMarker,但作为一个快速修复,我试图修复我的项目。首先,我包括了以下三个依赖项,以获得旧的速度包和类。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.25.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>在此之后,我的大部分代码在进行一些更改后都得到了修复。配置bean中剩下的最后一个问题是我的VelocityConfigurer。我正在尝试用一些属性插入一个VelocityEngine,然后用新创建的VelocityEngine创建一个VelocityConfigurer。就像我在春季启动更新之前做的那样。
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
@Configuration
public class MailConfig {
@Bean
@Primary
public VelocityConfigurer velocityEngineBean() {
VelocityEngine engine = new VelocityEngine();
engine.setProperty(Velocity.RESOURCE_LOADER, "ds");
engine.setProperty("ds.resource.loader.class", "XXX.CustomDataResourceLoader");
engine.setProperty("spring.velocity.checkTemplateLocation=false", "false");
engine.setProperty("spring.velocity.velocimacro.library", "XXX.vm");
engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Slf4jLogChute.class.getName());
engine.init();
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setVelocityEngine(engine);
return velocityConfigurer;
}}
但我得到了以下错误。错误:无法访问org.springframework.ui.velocity.VelocityEngineFactory
我可以弄清楚为什么它可以访问这个方法。带类的.jar在那里.VelocityEngineFactory
发布于 2022-04-14 18:17:37
这将无法工作,因为Spring 2.6需要SpringFramework5.3。速度支持为在SpringFramework4.3中被废弃,5.0移除。如果您想使用最新的、受支持的Spring版本(编写时为2.5.x或2.6.x ),则应该迁移到另一个模板引擎。
https://stackoverflow.com/questions/71872568
复制相似问题