In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about Spring Cloud upgrading the latest Finchley version of the pit to share with you. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Spring Boot 2.x has been released for a long time, and now that Spring Cloud has released a version of Finchley based on Spring Boot 2.x, let's do an overall framework upgrade for the project.
Before 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 updates
Before upgrading:
Org.springframework.cloud spring-cloud-starter-eureka-server
After upgrade:
Org.springframework.cloud spring-cloud-starter-netflix-eureka-server
Eureka Client
Because the configuration center needs to be registered with the registry as a service, Eureka Client needs to be upgraded, and other dependencies remain unchanged.
Eureka Client dependent updates
Before upgrading:
Org.springframework.cloud spring-cloud-starter-eureka
After upgrade:
Org.springframework.cloud spring-cloud-starter-netflix-eureka-client
Spring Cloud
The client instance IP in the registry does not display correctly
Because the IP address configuration of the Spring Cloud acquisition service client has changed.
Before upgrading:
${spring.cloud.client.ipAddress}
After upgrade:
${spring.cloud.client.ip-address}
Spring Security
General registries, configuration centers will use security encryption, will rely on spring-boot-starter-security components, there are two problems after the upgrade.
1. User name and password cannot be logged in
Because the parameters of Spring Security have been changed.
Before upgrading:
Security: user: name: password:
After upgrade:
Spring: security: user: name: password:
2. No instance is registered in the registry
As shown in the figure, without a registered instance, the two registries cannot register with each other.
Because Spring Security turns on all CSRF attack defenses by default, you need to disable / eureka defenses.
Add ignore configuration to the Application entry class:
@ EnableWebSecuritystatic class WebSecurityConfig extends WebSecurityConfigurerAdapter {@ Override protected void configure (HttpSecurity http) throws Exception {http.csrf () .ignoringAntMatchers ("/ eureka/**"); super.configure (http);}}
3. Configuration center cannot encrypt and decrypt.
After the upgrade, it is found that the access configuration center cannot read the configuration, nor can it encrypt and decrypt the configuration information. The access configuration center link jumps directly to the login page.
Now want to change back to the previous basic auth authentication method, find the source code to find that the automatic configuration jumped to the login page, now rewrite it.
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, it is to kill formLogin () and return to the previous basic auth authentication method, as shown in the following figure.
Now we can use the following command to encrypt and decrypt.
Such as decryption:
Curl http://xx.xx.xx.xx:7100/decrypt-d secret-u user:password
After restoring basic auth, the previous service needs to be encrypted to connect to the configuration center and is running normally again.
Maven
After upgrading to Spring Boot 2.x, I found that Spring Boot's Maven startup plug-in is not easy to use, mainly because Profile can not switch freely.
Before upgrading:
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
Failed to bind properties under 'eureka.instance.instance-id' to java.lang.String:
Description:Failed to bind properties under 'eureka.instance.instance-id' to java.lang.String:Property: eureka.instance.instance-idValue: ${spring.cloud.client.ipAddress}: ${spring.application.name}: ${spring.application.instance_id:$ {server.port}} Origin: "eureka.instance.instance-id" from property source "bootstrapProperties" Reason: Could not resolve placeholder' spring.cloud.client.ipAddress' in value "${spring.cloud.client.ipAddress}: ${spring .application.name}: ${spring.application.instance_id:$ {server.port}} "
The parameter spring.cloud.client.ipAddress can no longer be recognized.
Let's look at the source code:
# org.springframework.cloud.client.HostInfoEnvironmentPostProcessor@Overridepublic void postProcessEnvironment (ConfigurableEnvironment environment,SpringApplication application) {InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo (environment); LinkedHashMap map = new LinkedHashMap (); map.put ("spring.cloud.client.hostname", hostInfo.getHostname ()); map.put ("spring.cloud.client.ip-address", hostInfo.getIpAddress ()); MapPropertySource propertySource = new MapPropertySource ("springCloudClientHostInfo", map); environment.getPropertySources (). AddLast (propertySource);}
If we find that the original ipAddress has been changed to ip-address, then we can make corresponding corrections in the configuration center.
Note: changing to ip-address will not affect the previous version of the project, and will automatically parse and assign values correctly
Thank you for reading! This is the end of this article on "what are the pitfalls of upgrading the latest Finchley version of Spring Cloud?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 206
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.