在配置类里加上一个bean
@Bean
public SimpleMappingExceptionResolver simpleMappingExceptionResolver() {
SimpleMappingExceptionResolver exceptionResolver = new SimpleMappingExceptionResolver();
Properties properties = new Properties();
// 配置上未授权的跳转页面
properties.put("org.apache.shiro.authz.UnauthorizedException", unauthorizedUrl);
exceptionResolver.setExceptionMappings(properties);
return exceptionResolver;
}
该博客介绍了如何在Spring配置类中使用@Bean注解添加一个SimpleMappingExceptionResolver,以便在Apache Shiro遇到UnauthorizedException时,将用户重定向到特定的未授权页面。通过设置Properties对象,实现了异常映射,确保了权限控制的用户体验。
836

被折叠的 条评论
为什么被折叠?



