After introducing security, the service cannot be registered with Eureka

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/ – 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:

    static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable(); // Close csrf

The test is effective.

Read More: