Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Boot Migration From 1.5 to 2.0.5

DZone 's Guide to

Spring Boot Migration From 1.5 to 2.0.5

Thinking about upgrading your Spring Boot application?

· Java Zone ·
Free Resource

Thinking of upgrading your Spring Boot application? In this post, I’d like to walk you through the process of upgrading a Spring Boot 1.x app to Spring Boot 2.

Dependencies

Java

Spring Boot 2.x will no longer support Java 7 and below, with Java 8 as the minimum requirement.

It’s also the first version to support Java 9. There are no plans to support Java 9 on the 1.x branch. If you want to use the latest Java release and take full advantage of the framework, Spring Boot 2.x is your only option.

Gradle

The Gradle minimum supported version is 3.4.

The Gradle has many value-added features to have our dependency on the central repository.

To create fat jars, bootRepackage Gradle’s task gets replaced with bootJar and bootWar to build jars and wars respectively.

It is interesting to know that Spring Boot 2.x will no longer apply the dependency management plugin by default.

If you want Spring Boot dependency management, then you should add:

apply plugin: 'io.spring.dependency-management'


A few highlights regarding minimum required versions:

  • Tomcat minimum supported version is 8.5
  • Hibernate minimum supported version is 5.2

Steps to Upgrade

Step 1:

Assuming that you are using a Gradle build tool for building your application, your build.gradle file should look as follows:

buildscript {
repositories { 
   jcenter()
   mavenCentral()
}

dependencies {
  classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
 }
}

plugins {
   id 'org.springframework.boot' version '2.0.5.RELEASE'
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'

dependencies 
{
  compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
  compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'

}


Now, this will download all the required dependency jar files for the Spring Boot verison 2.0.5 release

Step 2:

Change the application properties as follows if you used any of the following properties in your application:

Servlet-Specific Server Properties

A number of server.* properties that are servlet-specific have moved to server.servlet:

Old property New property
server.context-parameters.* server.servlet.context-parameters.*
server.context-path server.servlet.context-path
server.jsp.class-name server.servlet.jsp.class-name
server.jsp.init-parameters.* server.servlet.jsp.init-parameters.*
server.jsp.registered server.servlet.jsp.registered
server.servlet-path server.servlet.path

Here is the list of commonly used application properties

Step 3:

Replace the deprecated methods and classes. Here are some of the deprecated classes that I came across and the respective classes

Deprecated Class New Class
org.springframework.web.context.request.RequestAttributes org.springframework.web.context.request.WebRequest
org.springframework.data.querydsl.QueryDslPredicateExecutor org.springframework.data.querydsl.QuerydslPredicateExecutor
org.springframework.boot.autoconfigure.web.DefaultErrorAttributes org.springframework.boot.web.servlet.error.DefaultErrorAttributes
org.springframework.web.context.request.ServletRequestAttributes org.springframework.web.context.request.ServletWebRequest
org.springframework.boot.web.support.SpringBootServletInitializer org.springframework.boot.web.servlet.support.SpringBootServletInitializer
WebConfigurer WebMvcConfigurer


Step 4:

Now, run your main class. Your application should be up and running.

Summary

In this article, we covered steps to migrating from Spring Boot 1.5.x to Spring Boot 2.0.5, where we discussed dependencies and how Java 8 becomes the minimum supported version.

Topics:
java ,spring ,spring boot 2.0 ,SPring Boot 1.5 ,Spring Boot 2.0.5 ,migration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}