<!-- bad practice in maven --> <dependency> <groupId>xxxx</groupId> <artifactId>xxxx</artifactId> <version>1.3.2</version> <type>jar</type> <scope>system</scope> <systemPath>${project.basedir}/libs/spring-4.0.9.jar</systemPath> </dependency>
You need to replace the jars with normal dependence. And, full test is required.
if you introduced two jars with different version, it will be dangerous. eg: two jackson will result in unexpected behavior on deserialization.
2.2. Manage version with dependency management
Manage the version of the jar(Eg: guava, common collections) manually is so hard, we can use maven’s parent or dependency management to control the version of jars.
Here is an example, you will use springboot as parent without any starter introduced.
<project> <!-- no jars will be introduced without explicit declare in dependencies --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> </parent> <dependencies> <!-- we will still use war formated --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- do as springboot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- exclude starters mannually --> <exclusions> <exclusion> <artifactId>spring-boot-starter</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>spring-boot-starter-tomcat</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> </dependencies> </project>
Now you have the same SpringMVC version with SpringBoot. If it works after test, continue to replace all dependencies.
Intellij IDEA plugin Dependecy Analyzer will be helpful for excluding jobs.
3. Migration of the Spring configuration from XML to Java
Since Spring 3, Java configuration is introduced. You can see cookbook here or read books like [Spring in action] on @Configuration annotation. This is a diff of how to convert the xml into java config.
For most servlet apps, there are two contexts in web.xml, the root context and web context.
3.1. Migration AppConfig
Replace XML based config to Annotation base config.
@Configuration // see why excluded https://stackoverflow.com/a/18684288/4016014 @ComponentScan(basePackages={"com.github.miao1007"},excludeFilters={ @Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class) @Filter(type=FilterType.ANNOTATION, value=Controller.class) @Filter(type=FilterType.ANNOTATION, value=RestController.class) }) // include your old config xml @ImportResource({"classpath*:root-config.xml"}) publicclassAppConfig { // you can also move your root-config.xml's bean to here little by little }
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { // this is the "replace" of contextConfigLocation in web.xml return application.sources(Application.class); } }
Remove the root context listener in web.xml or the context will be initiated twice.