Spring Boot 2.x has been released for a long time, and now Spring Cloud also released a version based on Finchley Spring Boot 2.x, and do a project together now to upgrade the overall framework.

 

Before upgrading => after upgrade

Spring Boot 1.5.x => Spring Boot 2.0.2

Spring Cloud Edgware SR4 => Spring Cloud Finchley.RELEASE

Server Eureka
Eureka Server relies update

Upgrade ago:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
1
2
3
4
升级后:

<dependency>
<the groupId> org.springframework.cloud </ the groupId>
<the artifactId> Starter-Spring-Cloud-Netflix-Eureka-Server </ the artifactId>
</ dependency>
. 1
2
. 3
. 4
the Eureka Client
because the configuration register as a service center needs to the registry, so it is necessary to upgrade Eureka Client, does not depend on other changes.

Eureka Client relies update

Upgrade ago:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
1
2
3
4
升级后:

<dependency>
<the groupId> org.springframework.cloud </ the groupId>
<the artifactId> Starter-Spring-Cloud-Netflix-Eureka-Client </ the artifactId>
</ dependency>
. 1
2
. 3
. 4
the Spring Cloud
client instance registry inside IP does not display correctly

Because Spring Cloud Services clients obtain IP address configuration changed.

Upgrade ago:

spring.cloud.client.ipAddress} {$
. 1
After:

spring.cloud.client.ip-address {} $
. 1
the Spring Security
general registry, configuration center will use secure encryption, will rely on spring-boot-starter-security component, there are a few problems after the upgrade two.

1, the user name and password can not log in

Because Spring Security parameters were changed.

Upgrade ago:

Security:
User:
name:
password:
. 1
2
. 3
. 4
upgraded:

Spring:
Security:
User:
name:
password:
. 1
2
. 3
. 4
. 5
2, not registered instance registry

As shown, the example is not registered, the registry can not register with each other two.

 

Because Spring Security is enabled by default for all CSRF attack defense, you need to disable / eureka defense.

Ignore Application Configuration increase in the import category:

@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void Configure (HttpSecurity HTTP) throws Exception {
http.csrf () ignoringAntMatchers ( "/ Eureka / **");.
Super.configure (HTTP);
}
}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
. 3, arranged the center can not encryption and decryption

After the upgrade center found that access to the configuration can not be read to the configuration, it can not encrypt and decrypt the configuration information, access the Configuration Center link to jump directly to the login page.

 

Now think of basic auth authentication before the back to find the source found to be automatically configured to jump to login page, now rewrite.

自动配置源码:
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();
}
1
2
3
4
5
6
7
8
9
10
重写之后:

@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/**").and().authorizeRequests().anyRequest()
.authenticated().and().httpBasic();
}

}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
actually put formLogin () get rid of, basic auth authentication before back, as shown in FIG.

 

Now we can use the following command encryption and decryption.

The decryption:
curl HTTP: //xx.xx.xx.xx: 7100 / Secret -u -d the decrypt the User: password

After restoring basic auth, before the service requires an encrypted connection configuration center has run normal.

Maven
found after upgrade to Spring Boot 2.x Spring Boot start of Maven plugin does not work well, mainly Profile can not be free to switch.

Upgrade ago:

Boot-Spring: RUN = -Drun.profiles profile profile1
. 1
After:

Boot-Spring: RUN = boot.run.profiles -Dspring-profile profile1
. 1
particularly refer to:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html

Summary
These are all finished stepped pit summed up solutions, practical problem-solving process is much more complicated. Version changes a little large, this has been successfully upgraded Spring Cloud dependent basis, and registration center (Eureka Server), the configuration center (Config Server).

Others, like Gateway instead of Zuul, and other components and then slowly upgrade, Spring Cloud's rapid development makes upgrades become very boring, we record all the pits during the upgrade stepped on. . .

Pit dead, has pledged to compile, run properly, pit do not know what else, just finished upgrade Finchley this official version, Spring Cloud has just released a Finchley.SR1, feeling Spring Cloud became a school does not move campaigns. . .

Guess you like

Origin www.cnblogs.com/lykbk/p/qwewqe32423423.html
Recommended