近日接手了一个Struts + Spring + Mybatis 的项目后来又加入Spring Mvc,试着在原有的框架上开发了几个功能以后,实在没法忍受其开发效率,决定升级为SoJpt Boot 使用 JFinal特性进行开发。所以有了如下的升级过程。java
思路: 升级为Spring boot 加入SoJpt Boot,改为maven 项目便可(这里使用了SoJpt Boot脚手架一步搞定)。mysql
1. 根据本身的项目是否为先后台分离下载对应的SoJpt Boot 脚手架, 这里我下载了SoJpt-Boot-Staging-mysql-v1.2 而后根据http://sojpt.com/doc/5-1 教程新建项目。web
2. 把原项目的代码所有拷入新建的项目。若有问题可参考spring mvc 迁移至spring boot 的相关解决方案。 这里为了简单直接引入以前spring 的配置文件applicationContext.xml (这里使用了打war包的方式,也修改了pom.xml中的bulid)spring
@SpringBootApplication @ImportResource("classpath:applicationContext.xml") public class SoJptSpringbootApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SoJptSpringbootApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SoJptSpringbootApplication.class); } }
3.删除 applicationContext.xml中的有关数据源与事务的配置。这些以spring Boot 的方式来配置。sql
4.由于以前项目不是maven项目,因此这里把相关的jar 包找到其对应的maven依赖引入便可。mvc
5.将以前web.xml配置以注解的方式进行配置,下面给出一个过滤器的配置案例:app
@Bean public FilterRegistrationBean<StrutsPrepareAndExecuteFilter> struts2() { FilterRegistrationBean<StrutsPrepareAndExecuteFilter> registration = new FilterRegistrationBean<>(); registration.setFilter(new StrutsPrepareAndExecuteFilter()); registration.setName("struts2"); registration.addUrlPatterns("/*"); registration.setOrder(3); //值越小,Filter越靠前。 return registration; }
到这里全部的主要的配置就结束了。框架
备注: 其余根据Spring Boot, SoJpt Boot 与 JFinal的文档配置对应的数据源。热加载报错的话,可参考Spring Boot devtools的解决方法,在META-INF/spring-devtools.properties 下加入须要热加载的jar便可,以下:maven
restart.include.sojpt.boot=/sojpt-boot-2.5.8-4.3.jar restart.include.sojpt.boot.stater=/sojpt-boot-spring-boot-starter-2.5.8-4.3.jar restart.include.jrobin=/jrobin-1.5.9.jar restart.include.javamelody=/javamelody-core-1.79.0.jar restart.include.javamelody.stater=/javamelody-spring-boot-starter-1.79.0.jar restart.include.spring.tx =/spring-tx-5.1.9.RELEASE.jar