该问题可能是由于CSRF保护所致。如果用户不会在Web浏览器中使用您的应用程序,则可以安全地禁用CSRF保护。否则,您应确保在请求中包含CSRF令牌。
要禁用CSRF保护,可以使用以下命令:
@Configuration@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter implements ApplicationContextAware { @Override protected void configure(HttpSecurity http) throws Exception { http // ... .csrf().disable(); } @Override protected void registerAuthentication(AuthenticationManagerBuilder authManagerBuilder) throws Exception { authManagerBuilder .inMemoryAuthentication() .withUser("user").password("password").roles("ADMIN"); }}


