When building the Eureka service of springcloud, security was introduced for security. However, it was found that the Eureka client could not register. The error log is as follows:
DiscoveryClient_ EUREKA-CLIENT/10.168.211.109:8001 – was unable to send heartbeat!
Later, I inquired about the Security version of the project (spring boot starter security in version 2.3.2.release introduces the security configuration of 5.3. X). If the version is too high, it will be changed by default When CSRF (Cross Site Request Forgery) is turned on, you need to turn it off. The steps are as follows:
Add the following code into the startup file:
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); // Close csrf
super.configure(http);
}
}
The test is effective.