Springboot + swagger2 reports error 403 Forbidden
Error reporting reason
When creating a springboot project, if spring security dependencies are introduced into the POM file, after spring boot starter security, springboot will enable authentication by default, and also enable CSRF (Cross Site Request Forgery Prevention) verification by default. Therefore, the post request will be intercepted, that is, an error 403 Forbidden will be reported, and the get request will not be intercepted
Solution
Use ignore to ignore interception and manually turn off CSRF protection. Remember to turn on annotation @ enablewebsecurity manually
@EnableWebSecurity
public class WebSecurityCongfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable();
}
}
Read More:
- Springboot error about swagger startup [How to Solve]
- Springboot2.6.X configurate swagger error [How to Solve]
- Springboot Integrate Swagger2 Error: Failed to start bean ‘documentationPluginsBootstrapper‘;
- [Solved] Springboot integrate swagger error: Failed to start bean ‘documentationPluginsBootstrapper‘
- [Solved] Springboot integrate swagger error: failed to start bean ‘documentationpluginsbootstrapper‘
- [Solved] Springboot Error: swagger-UI/index.html Access Error 404
- Tomcat cross server upload error 403forbidden [How to Solve]
- How to Solve Swagger error: IllegalStateException
- [Solved] swagger Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullP
- [Solved] Swagger Startup Error: java.lang.NumberFormatException: For input string: ““
- How to Solve Swagger Always Displays “basic-error-controller” Issue
- [Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException
- How to Solve Swagger error: typeerror: failed to fetch
- [Solved] Swagger request error: error:getaddrinfo ENOTFOUND
- Configuration of springboot + Druid connection pool
- The problem of date format conversion between springboot and front end
- Springboot controls the startup of rabbitmq through configuration files
- [Solved] Springboot2.x ElasticSearch Error: availableProcessors is already set to [4], rejecting [4]
- How to Solve Springboot configurate environment file Error
- springboot sqlserver druid reward: validateConnection false