层主用的环境是spring boot+swagger
用的shiro做的拦截
首先导入swagger ui依赖的jar包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
然后配置swagger(指明swagger路径)
如:
@EnableSwagger2
@Configuration
@ComponentScan("***.controller")
public class SwaggerConfig{
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("***.controller"))
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Swagger UI---- RESTful APIs")
.description("接口对接swagger服务")
.version("1.0")
.description("该swagger ui仅是一个参考")
.build();
}
这里面重要的是路径声明和
@EnableSwagger2
@Configuration
在***.controller:
@Api(tags = “操作员管理”):类上声明
@ApiOperation(value = “登录”):方法上声明
因为我用到了拦截器,因此需要配置放行swagger:
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/webjars/**", "anon");