spring boot shiro 权限验证注解报异常不跳转403

spring boot shiro 权限验证注解报异常不跳转403


webmvc 配置类添加配置

@Configuration
@EnableWebMvc  // Optionally setup Spring MVC defaults (if you aren't using
               // Spring Boot & haven't specified @EnableWebMvc elsewhere)
public class MvcConfiguration extends WebMvcConfigurerAdapter {
  @Bean(name="simpleMappingExceptionResolver")
  public SimpleMappingExceptionResolver
                  createSimpleMappingExceptionResolver() {
    SimpleMappingExceptionResolver r =
                new SimpleMappingExceptionResolver();

    Properties mappings = new Properties();
    mappings.setProperty("DatabaseException", "databaseError");
    mappings.setProperty("UnauthorizedException","403");  //捕捉权限异常跳转403页面
    r.setExceptionMappings(mappings);  // None by default
    r.setDefaultErrorView("error");    // No default
    r.setExceptionAttribute("ex");     // Default is "exception" //页面上获取异常信息变量名
   // r.setWarnLogCategory("example.MvcLogger");     // No default 日志处理
    return r;
  }
  ...
}
参考:https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc

你可能感兴趣的:(Spring,spring,boot)