springboot集成swagger2(shiro配置)

 

1.maven配置


    io.springfox
    springfox-swagger2
    2.9.2


    io.springfox
    springfox-swagger-ui
    2.9.2

2.Swagger2Config配置

@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors
            .basePackage("hryr.controller")).paths(PathSelectors.any()).build();
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("springboot利用swagger构建api文档")
            .description("简单优雅的restfun风格,https://www.baidu.com/")
            .termsOfServiceUrl("https://www.baidu.com/")
            .version("1.0")
            .build();
}

3.接口注解配置

@ApiOperation(value = "注册", notes = "注册")
@ApiImplicitParam(name = "appUser", value = "用户详细实体appUser", required = true, dataType = "AppUser")
@RequestMapping(value = "regist", method = RequestMethod.POST)
public String register(@RequestBody AppUser appUser) {}
忽略加@ApiIgnore

4.设置shiro不拦截配置

filterChainDefinitionMap.put("/swagger-ui.html", "anon");
filterChainDefinitionMap.put("/swagger-resources", "anon");
filterChainDefinitionMap.put("/swagger-resources/configuration/security", "anon");
filterChainDefinitionMap.put("/swagger-resources/configuration/ui", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");


5.访问 http://localhost:8103/swagger-ui.html

 

编辑参数,执行点击try it out,才会出现请求按钮,楼主当时找了半天

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37162911/article/details/81507154

你可能感兴趣的:(springboot)