彻底解决Spring Boot1.5.X版本不支持Velocity模板引擎的方法
最近在做关于Spring Boot开发的项目,因为项目中要用到Velocity的模板引擎,而现在新版本在官网上已经不支持Velocity了。
不能加入velocity相关的依赖
在http://velocity.apache.org/download.cgi#engine上看到有相关的依赖jar包和配置信息,首先下载jar包:
下载的是:
engine-core | velocity-engine-core-2.0.jar |
---|
下下来之后是这样一个东西:
然后在Idea中导入jar包,点击file中的project structure:
然后选择modules中的dependencies,点击那个+号,找到你刚刚下载好的文件,就可以导入外部的jar包了。
因为当初官网初始化Spring的时候没有选择模板引擎,现在需要自己手动添加:
找到pom.xml文件,在<dependencies></dependencies>中间加入:
文本格式:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-velocity</artifactId> </dependency> <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>
然后手动将Spring Boot的版本改小。原来是Spring Boot 1.5.15,现在改成1.4.0,这个版本支持Velocity。
改好后,保存,运行,如果你在运行之后能看到这样的一行,说明你已经成功的导入了velocity的依赖
然后就可以在网页中打开自己写的.vm模板文件了。