Swagger UI 配置

层主用的环境是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");

设置完毕大概是这个样子

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值