原SSM项目迁移至Springboot项目:
1、使用IDEA的File->New->Project->Spring Initializr新建SpringBoot新的空项目;
2、将原SSM项目中的项目首先整理为maven管理的项目,把WEB-INF下的lib中的jar包都迁移到私服仓库中,将项目整理为标准maven结构,src文件夹与pom.xml;
3、将原项目src与pom复制到新的SpringBoot项目;
4、使用maven的clean,install来尝试编译打包,解决编译打包过程中的问题;(在原项目中引入了一堆springframework的spring-*包,可以尝试去掉,引用springboot下的spring-boot-starter-web包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>;若打包之后xml文件没有打进去,可以尝试在build中增加如下配置:
<resources> <resource> <directory>${basedir}/src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources>)
问题记录:
1、打包时报错:无法访问orgapachehttpannotationThreadSafe
解决方案:增加httpcore依赖:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
2、maven构建时报错:ClassNotFoundException: org.springframework.context.event.GenericApplication
原因:原SSM项目的pom完全复制到springboot项目中,包含了原来的springframework下的各个依赖,与springboot下的web依赖之间冲突
解决方案:去掉原springframework的包,使用springboot下web包中的spring组件,然后根据需要增加依赖,项目中使用了quartz,就增加两个依赖:
<dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency>
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.0.6.RELEASE</version> </dependency>
3、启动时报:java.lang.ClassNotFoundException: org.apache.ibatis.annotations.Mapper
解决方案:
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.7</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency>