使用springboot整合shiro后再整合swagger,及出现的URL [/swagger-ui] again. Check your ViewResolver setup!问题

 

首先,整合swagger的话很简单,这里首先说说之前出现的问题,

如果你加入了jsp及页面的跳转,这个时候很可能出现

Circular view path [swagger-ui]: would dispatch back to the current handler URL [/swagger-ui] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)或者是

这个问题是你的页面在跳转的时候出现的问题,之前我也出现这种问题,原因是如下有的人说要加下面的一个类进行一个指定位置

@SuppressWarnings("deprecation")
@Configuration
public class WebMVCConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
    }
}

 其实,并不需要上边的那些注释位置,主要原因是我的controller中存在handler不能处理转发的路径,如下

       /**
		 * 页面转发, 显示main.jsp内置页面信息
		 */
		@RequestMapping("/commons/{path}")
		public String dispathcer(@PathVariable String path){
			return "commons/"+path;
		}
		
		/**
		 * 页面转发方法. 实现main.jsp显示
		 * @param path
		 * @return
		 */
		@RequestMapping("/{path}")
		public String toLogin(@PathVariable String path){
			return path;
		}

         在这里发生了多次的页面的跳转,导致系统不知道如何跳转才出现Hint: This may be the result of an unspecified view, due to default view name generation.这个错误,当我把这个注释掉之后就可以显示swagger-ui.html了

1、在pom.xml文件中添加swagger依赖

	    <!-- 集成swagger接口文档 -->
	    <dependency>
	        <groupId>io.springfox</groupId>
	        <artifactId>springfox-swagger2</artifactId>
	        <version>2.8.0</version>
	    </dependency>
	    <!-- swagger-ui -->
	    <dependency>
	        <groupId>io.springfox</groupId>
	        <artifactId>springfox-swagger-ui</artifactId>
	        <version>2.8.0</version>
	    </dependency>

2、编写swagger配置类

@Configuration
@EnableSwagger2
@EnableAutoConfiguration
@ComponentScan("cn.zkhh.controller")
public class Swagger2 {

	@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.zkhh"))
                .paths(PathSelectors.any())
                .build();
    }
	
	
	 //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring Boot 测试使用 Swagger2 构建RESTful API")
                //创建人
                .contact(new Contact("贾洋洋", "https://blog.csdn.net/null111666", ""))
                //版本号
                .version("1.0")
                //描述
                .description("API 描述")
                .build();
    }
}

3、在启动类中要配置路径,以便可以扫描到swagger,并开启swagger的注解,如图

 

4、然后启动之后,访问地址http://localhost:端口/swagger-ui.html,即可,如图

5、如果你是使用springboot也整合了shiro的权限管理控制的话,就需要开放swagger的资源路径,否则也是访问不到swagger接       口资源的,开发路径如下

        /**swagger拦截配置*/
        filterChainDefinitionMap.put("/swagger-ui.html", "anon");
        filterChainDefinitionMap.put("/swagger-resources/**", "anon");
        filterChainDefinitionMap.put("/swagger-resources", "anon");
        filterChainDefinitionMap.put("/v2/api-docs", "anon");
        filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");

这样,在整合shiro后依然可以访问swagger

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值