background

The project has been using Spring Cloud Dalston.sr5 until December 2018, when the software lifecycle of this release will end, and the release will need to be upgraded for subsequent security and maintenance purposes. After analyzing the changes of later versions of VERSION D from the official website, it is found that most components are basically compatible. Only some of the changes that have a significant impact on the upgrade are listed here:

  • Edgware: The dependent Spring Boot version upgrade is still 1.5, with many component names changed
  • Finchley: Dependent Spring Boot version upgrade to 2.0, real big upgrade, big change
  • Greenwich: dependent spring boot version upgraded to 2.1 with java11 support

Then we searched the experience and difficulty of others on the network and decided to upgrade the current Spring Cloud directly to the latest version: Greenwich.SR1

Detailed steps to upgrade and pit encountered

Spring-cloud-dependencies versions are available from Dalston.sr5 to Greenwich.SR1

	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Dalston.SR5</version>
	-->
	<artifactId>spring-cloud-dependencies</artifactId>
	<version>Greenwich.SR1</version>
Copy the code

The Spring Boot version was upgraded from 1.5.13 to 2.1.4

The < artifactId > spring - the boot - starter - parent < / artifactId > < version > 1.5.13. RELEASE < / version > -- > < artifactId > spring - the boot - starter - parent < / artifactId > < version > 2.1.4. RELEASE < / version >Copy the code

Spring Cloud component artifactId name change: old on the left, new on the right

spring-cloud-starter-eureka --> spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-eureka-server  -->  spring-cloud-starter-netflix-eureka-server
spring-cloud-starter-feign --> spring-cloud-starter-openfeign
spring-cloud-starter-hystrix -> spring-cloud-starter-netflix-hystrix
Copy the code

Modify the corresponding artifactId name in pom.xml to the latest name. See here for other artifactId changes: E version github.com/spring-proj…

The change of Feign

Feign In addition to the artifactId name of the component mentioned above, which is renamed spring-Cloud-starter-OpenFeign, the following parts have changed:

Package name changed:

org.springframework.cloud.netflix.feign.**.java -> org.springframework.cloud.openfeign.**.java
Copy the code

@feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: @feignClient: “The bean ‘icc-authority.FeignClientSpecification’, defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.”

The solution is to add contextId to the @feignClient annotation to give the bean ID as follows:

	@FeignClient(name="authority", fallbackFactory = IAccountServiceFallbackFactory.class, contextId = "accountService")
	public interface IAccountService {
		
	}
Copy the code

Feign Connection Pooling Because Spring Cloud D version of Fegin uses HttpClient for connection pooling, there are too few configurable items to create connection pool objects by default and there may be half-connected connections in the connection pool. So I implemented my own HttpClient instance. The G version, if the implementation Httpclient do connection pool, default to create your own system of Httpclient object, in addition to observe source HttpClientFeignLoadBalancedConfiguration create an Httpclient code, Not only add timer to close abnormal connections to solve the problem of half-connections, connection pool parameters are configurable.

Solution: Plan 1. So get rid of your own HttpClient instance and use the default HttpClient instance scheme 2. Httpclient (@priMAY); httpClient (@priMAY); httpClient (@priMAY)

@Bean @Primary public HttpClient httpClientDefault(FeignHttpClientPoolConfiguration feignHttpClientPoolConfiguration){ HttpClient HttpClient =... .; return httpClient; }Copy the code

If Feign is used to implement file uploading, the following exceptions will be thrown: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: The request was rejected because no multipart boundary was found IO. Making. Openfeign. Form. Feign – form and IO. Making. Openfeign. Form. The feign – form – spring from 3.0.3 version upgrade to 3.8.0 Commons – Fileupload upgraded to 1.4

The jedis-related component could not be found

The new version uses Spring Data Redis 2.0, which has removed jedis and uses the default Lettuce component solution 1: If the code does not indicate that jedis is used, it is recommended to use this solution and then modify the redis configuration parameters as prompted by the IDE

Clients </groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency>Copy the code

Druid Connection pool version upgrade

Throw an exception: under Caused by: Java. Lang. ClassNotFoundException: org.. Apache log4j reasons: new version the Spring do not use log4j Boot, but support log4j2 solution: 1. Set the filters attribute of drui to log4j2:2. Upgrade the com.baba.druid. jar package to 1.1.16

Distribution plugin PageHelper

Fault: PageHelper does not work properly Cause: Current pagehelper-spring-boot-starter does not support Spring Boot 2.1.x Solution: 1.com.github. Pagehelper: Pagehelper-spring-boot-starter Upgrade to 1.2.10, used to support Spring Boot 2.1.x 2. Corresponding com.github. Pagehelper: PageHelper upgraded to 5.1.8

Property configuration changes:

Server.context-path: authority –> server.servlet.context-path: Authority Upload file parameters: Spring, HTTP multipart. * – > spring. Servlet. Multipart. * such as the original spring. HTTP multipart. MaxFileSize: 5 MB – > Spring. Servlet. Multipart. MaxFileSize: 5 Mb here at the same time 5 Mb Mb must be in capital letters, must be 5 Mb, otherwise it will throw an exception: failed to convert java.lang.String to @org.springframework.boot.convert.DataSizeUnit org.springframework.util.unit.DataSize

@notblank, @notempty annotations are already included in JSR303 and you don’t need to use hibernate annotations anymore

org.hibernate.validator.constraints.NotBlank –> javax.validation.constraints.NotBlank org.hibernate.validator.constraints.NotEmpty –> javax.validation.constraints.NotEmpty

zipkin

In the new version, @enableZipkinServer has been marked @deprecated, and running Zipkin as a custom build service is no longer recommended. Curl -ssl zipkin. IO /quickstart… Java – jar zipkin. | bash – s jar see here in detail: github.com/apache/incu… Github.com/apache/incu…

Other:

After the upgrade, often throw did not find the class exception: Java. Lang. To this kind of mistake, NoClassDefFoundError find corresponding jar through as long as it can solve the upgrade to the latest version. This also tells us that if we want to use third-party components, we must use components that are active in the community. Otherwise, we must replace the functionality of this component with a new component if it is not compatible with other components due to security issues or system upgrades.

Since we are using the most recent version of Spring Cloud, upgrading dependent jars is usually ok as long as you upgrade to the latest version

Spring Cloud Netflix enters the maintenance mode of the project

With the exception of the Spring-Cloud-Netflix-Eureka -* and spring-Cloud-Netflix-concurrency -limits modules, all of Netflix is in maintenance mode. ○ Spring-cloud-Netflix-Archaius ○ Spring-cloud-Netflix-Hystrix-Contract ○ Spring-cloud-Netflix-Hystrix-dashboard ○ Spring-cloud-netflix-hystrix-stream ○ Spring-cloud-Netflix-hystrix ○ Spring-cloud-Netflix-ribbon ○ Spring-cloud-netflix -stream ○ Spring-cloud-Netflix -turbine ○ Spring-cloud-Netflix – Zuul

The module on the left in the following table has also entered the maintenance module, and its future replacement is on the right

  • Hystrix has entered maintenance mode, it is recommended to use Resillence4j for replacement. The Hystrix Dashboard and Turbine will also be eliminated. It is recommended to use Resillence4j’s own Micrometer for replacement. Resillence4j is incubated at github.com/spring-clou…
  • Ribbion has been replaced by Spring Cloud Loadbalancer.
  • Zuu1 1 has been replaced by Spring Cloud GateWay: Spring Cloud GateWay and Zuul 1.x performance comparison: www.itmuch.com/spring-clou…
  • Archaius 1’s alternative to Spring Boot External Config + Spring Cloud Config

What is maintenance mode: Spring Cloud does not add new functionality to corresponding modules, but they do fix bugs and security issues and accept pull requests from the community. Spring Cloud is guaranteed to continue supporting the above modules for at least a year even after the Greenwich version is widely adopted