Spring Boot 1.5.x to 2.x Migration Story

Mark Reinhold, chief architect of Oracle’s Java Platform Group, says on his blog “For Java to remain competitive it must not just continue to move forward — it must move forward faster.”

After 2018 java released every 6 months so what will happen spring boot project?

Spring boot 1.x line reached end of life. They announced at august 2019 own blog site. Unlike previous versions, the migration to the newer releases have some changes.

Why upgrade?

  • Upgrading java version

How

Our spring boot project dependencies :

https://github.com/erolyapici/spring-boot-upgrade/tree/master/1.5

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>

And changed config

server:
servlet-path: /application-name
spring:
profiles: dev,test

to

server:
servlet:
context-path: /application-name
spring:
config:
activate:
on-profile: dev,test

Spring Boot Actuator Changes

  • All endpoints have moved to /actuator by default.
    If you want to change use this config
management.endpoints.web.base-path=/

Spring actuator changed config =>

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#configuration-keys-structure

Prometheus Changes

Spring Boot 2.0 no longer ships with its own metrics APIs. Instead we rely on micrometer.io for all application monitoring needs.

add prometheus dependency on pom xml

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Add new config

spring.jmx.enabled=true
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/
management.metrics.export.prometheus.enabled=true

Consul Changes

Reference https://docs.spring.io/spring-cloud-consul/docs/3.0.1/reference/html/

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Caching

Dedicated Hazelcast Auto-configuration for Caching

It is no longer possible to auto-configure both a general HazelcastInstance and a dedicated HazelcastInstance for caching. As a result, the spring.cache.hazelcast.config property is no longer available.

GuavaCacheManager

Support for Guava has been dropped in Spring Framework 5. If you were are using GuavaCacheManager, Caffeine (com.github.ben-manes.caffeine:caffeine) and CaffeineCacheManager should be used instead.

GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder()
.expireAfterWrite(1, CACHE_TIME_UNIT));
to
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(Caffeine.newBuilder()
.expireAfterWrite(1, CACHE_TIME_UNIT));

RedisCacheManager

The Redis CacheManager implementation has been reworked significantly, make sure to review the reference documentation.

JUnit5

spring-boot-starter-test now provides JUnit 5 by default. JUnit 5’s vintage engine is included by default to support existing JUnit 4-based test classes so that you can migrate to JUnit 5 when you are ready to do so. It is also possible to use a mixture of JUnit 4- and JUnit 5-based test classes in the same module. This allows you to migrate to JUnit 5 gradually if you wish.

Circuit Breaker

spring-cloud-netflix-hystrix removed at spring Cloud 2020.0 release.

You can add the dependency your project.

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring-cloud-starter-netflix-hystrix.version}</version>
</dependency>

Mockito Updates

Remove old mockito dependecy from pom.xml . The new mockito dependency comes from new boot version.

MockitoAnnotations.initMocks(this) to MockitoAnnotations.openMocks(this)

org.mockito.runners.MockitoJUnitRunner to org.mockito.junit.MockitoJUnitRunner

import static org.mockito.Matchers to import static org.mockito.ArgumentMatchers

In conclusion, we can say there few changes to migration spring boot 1.5.x to 2.x can be easily overcome. Maybe I may not written the minor changes but I will update If I get new changes.

Love Java, PHP, JavaScript, Python. Scrum Master, Team Lead