Spring Boot 2.x has been released for a long time, and now spring Cloud has released the Finchley version based on spring boot 2.x, and now it's time to do an overall framework upgrade for the project.
Pre-upgrade = + After upgrade
Spring Boot 1.5.x = Spring boot 2.0.2
Spring Cloud Edgware SR4 = Spring Cloud Finchley.release
Eureka Server
Eureka Server Dependent Update
Before upgrade:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId></dependency>
After Upgrade:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency>
Eureka Client
Because the configuration center needs to be registered as a service to the registry, the Eureka Client needs to be upgraded, and other dependencies are not changed.
Eureka Client Dependency Update
Before upgrade:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId></dependency>
After Upgrade:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>
Spring Cloud
Client instance IP inside the registry is not displayed correctly
Because the Spring Cloud gets the service client IP address configuration changed.
Before upgrade:
${spring.cloud.client.ipAddress}
After Upgrade:
${spring.cloud.client.ip-address}
Spring Security
The general registry, the configuration center will use secure encryption, will rely on spring-boot-starter-security
components, after the upgrade there are a few two issues.
1. User name and password cannot be logged in
Because the parameters of Spring Security are changed.
Before upgrade:
security: user: name: password:
After Upgrade:
spring: security: user: name: password:
2. Registration Center does not have a registered instance
, two registries cannot register with each other without registering an instance.
Because Spring Security opens all csrfxxx defenses by default, you need to disable/eureka's defenses.
In the Application Ingress class, add the Ignore configuration:
@EnableWebSecuritystatic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().ignoringAntMatchers("/eureka/**"); super.configure(http); }}
3, the configuration center cannot add decryption
After the upgrade, the Discovery Access Configuration Center cannot read to the configuration, and can not decrypt the configuration information, access the Configuration Center link directly to the login page.
Now want to change back to the basic Auth authentication method, find source discovery is automatic configuration jumped to the login page, now rewrite.
Automatically configure the source code:
Org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter#configure ( org.springframework.security.config.annotation.web.builders.HttpSecurity)
protected void configure(HttpSecurity http) throws Exception { logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity)."); http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin().and() .httpBasic();}
After rewriting:
@EnableWebSecuritystatic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().ignoringAntMatchers("/**").and().authorizeRequests().anyRequest() .authenticated().and().httpBasic(); }}
In fact, is to formLogin()
kill, and return to the previous basic Auth authentication method, as shown.
Now we can use the following command to decrypt it.
such as decryption:
Curl http://xx.xx.xx.xx:7100/decrypt-d secret-u User:password
After the basic auth is restored, the previous service requires the encrypted Connection Configuration Center to function again.
Maven
After upgrading to spring boot 2.x, it is not easy to find the spring boot Maven boot plugin, mainly the profile cannot be switched freely.
Before upgrade:
spring-boot:run -Drun.profiles=profile1
After Upgrade:
spring-boot:run -Dspring-boot.run.profiles=profile1
For details, please refer to:
Https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html
Summarize
The above are all the holes summed up the solution, the actual problem solving process far more complex. The version has changed a bit, and this time it has successfully upgraded the Spring Cloud base dependency, and the registry (Eureka server), configuration Center (config server).
Other things like Gateway instead of Zuul, and other components are slowly upgrading, the rapid development of Spring Cloud makes the upgrade become very sore, this article records all the pits that have been trampled during the upgrade ...
The pit is dead, has guaranteed compiles, the operation is normal, other also has what pit does not know, just upgraded Finchley This official version, Spring Cloud has just released the FINCHLEY.SR1, feels spring cloud has become the learning not to move the series ...
@ All yards farmers: did you upgrade? What kind of hole did you meet? Welcome Message!
Recommended: Spring Boot & Cloud's Strongest technology tutorials
Scan attention to our public number, dry foods updated daily.
Spring Cloud Upgrades the latest Finchley version, stepping on all the pits!