springboot+springsecurity+swagger2

一、POM.xml

<dependency>

    <groupId>io.springfox</groupId>

    <artifactId>springfox-swagger2</artifactId>

    <version>2.9.2</version>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

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

<version>2.9.2</version>

</dependency>

二、配置类


三、静态资源路径转换配置类(实现webMvcConfigurer接口)

四、放开权限

.antMatchers("/swagger-ui.html").permitAll()

.antMatchers("/swagger-resources/**").permitAll()

.antMatchers("/images/**").permitAll()

.antMatchers("/webjars/**").permitAll()

.antMatchers("/v2/api-docs").permitAll()

.antMatchers("/configuration/ui").permitAll()

.antMatchers("/configuration/security").permitAll()


如果出现Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually则表示有资源漏设置,补permit即可。

五、注意事项

1.对@RequestBody的map类型参数支持不太好,没法给出示例(得自己扩展,具体可以百度一下,有示例)

2.对@RquestBody的实体类型的支持比对map类型参数支持好,可通过@ApiModel @ApiModelProperties来设置哪些属性要隐藏,哪些必填等。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。