写一个配置类如下
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
import java.util.Properties;
@Configuration
public class ExceptionConf {
@Bean
public SimpleMappingExceptionResolver resolver() {
SimpleMappingExceptionResolver resolver = new SimpleMappingExceptionResolver();
Properties properties = new Properties();
//后面加上你的处理页面即可
properties.setProperty("org.apache.shiro.authz.UnauthorizedException", "/notRole");
resolver.setExceptionMappings(properties);
return resolver;
}
}

本文介绍如何使用Spring框架配置异常处理,通过创建一个配置类,实现对特定异常的映射,如UnauthorizedException,将其定向到/notRole页面。
1295

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



