当前位置: 代码迷 >> 综合 >> Shiro,Swagger2,Unable to render this definition问题
  详细解决方案

Shiro,Swagger2,Unable to render this definition问题

热度:27   发布时间:2023-10-19 00:34:29.0

swagger-ui.html访问报错


   在用swagger测试接口时,一直报错,但是查看了配置并没有问题,最后发现是shiro给拦截了。报错截图如下:
Shiro,Swagger2,Unable to render this definition问题
   解决方案,在shiro中增加swagger相关的放行操作

 @Beanpublic ShiroFilterChainDefinition shiroFilterChainDefinition() {
    DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();chainDefinition.addPathDefinition("/static/**", "anon");chainDefinition.addPathDefinition("/files/**", "anon");chainDefinition.addPathDefinition("/global/sessionError", "anon");/*swagger相关不拦截操作开始*/chainDefinition.addPathDefinition("/swagger-ui.html/**", "anon");chainDefinition.addPathDefinition("/swagger-resources/**", "anon");chainDefinition.addPathDefinition("/v2/api-docs", "anon");chainDefinition.addPathDefinition("/webjars/**", "anon");/*swagger相关不拦截操作结束*/chainDefinition.addPathDefinition("/kaptcha", "anon");chainDefinition.addPathDefinition("/preview/**", "anon");chainDefinition.addPathDefinition("/login", "anon");chainDefinition.addPathDefinition("/logout", "logout");chainDefinition.addPathDefinition("/**", "user");return chainDefinition;}
  相关解决方案