Solution :
According to the spring.io:
When should you use a CSRF protection? Our recommendation is to use a CSRF protection for any request that could be processed by the browser by normal users. If you are only creating the service that is used by the non-browser clients, you will likely want to disable a CSRF protection.
So to disable CSRF protection you can refer the below code :
@Configuration
public class RestSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
Note: The CSRF protection is enabled by default with a Java Configuration
Hope it will help you in fixing your error.