我希望控制器方法中抛出的异常被转换为500 internal server error ,但是无论控制器方法内部发生什么异常,我都会在客户端收到405 method not allowed异常。
笔记:
请求映射没有任何问题,因为当我调试它时它会进入预期的方法。但是,当控制器方法抛出异常时,我的客户端中出现“405 方法不允许”
笔记2:
我尝试捕获异常并抛出HttpServerErrorException
适当的错误代码和消息,但没有任何改变!
编辑:
我确实使用弹簧安全,这是配置:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
/*
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/session/**").permitAll()
.antMatchers("/app/**").permitAll()
.antMatchers("/lib/**").permitAll()
.antMatchers("/templates/**").permitAll()
.antMatchers("/dial/**").permitAll()
.antMatchers("/names/**").permitAll()
// .antMatchers("/workflows/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/#/login").permitAll();
http.csrf().disable();
http.exceptionHandling().defaultAuthenticationEntryPointFor(
new UnauthorizedLoginUrlAuthenticationEntryPoint("/login.html"),
new ELRequestMatcher("hasHeader('X-Requested-With','XMLHttpRequest')"));
/* .logout()
.permitAll();*/
}
}