Swagger2集成进Springboot简单说明

2018-11-28  本文已影响0人  marksman_e902

1.Maven依赖:

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger2</artifactId>

<version>2.8.0</version>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger-ui</artifactId>

<version>2.8.0</version>

</dependency>

2.Swagger配置:

@Configuration

@EnableSwagger2

@ComponentScan(basePackages = {"com.whz.serverdemo.controller"})//控制器扫描

public class Swagger {

@Bean

    public Docket customDocket() {

return new Docket(DocumentationType.SWAGGER_2)

.apiInfo(apiInfo())

.select()

.build();

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("API接口文档")

.description("描述")

.termsOfServiceUrl("url")

.version("1.0")

.build();

}

}

3.Shiro配置过滤器(采用Shiro权限控制才配置)

ShiroConfiguration→ShiroFilterFactoryBean中配置如下

filterChainDefinitionManager.put("/swagger-ui.html","anon");

filterChainDefinitionManager.put("/swagger-resources/**","anon");

filterChainDefinitionManager.put("/v2/api-docs/**","anon");

filterChainDefinitionManager.put("/webjars/springfox-swagger-ui/**","anon");

4.控制器接口解释

...

上一篇下一篇

猜你喜欢

热点阅读