美文网首页
SpringBoot集成Security,Swagger遇到的坑

SpringBoot集成Security,Swagger遇到的坑

作者: 陶渤 | 来源:发表于2020-08-07 17:37 被阅读0次

1.在使用SpringBoot开发项目的过程中同时集成Spring Security和Swagger 3.0.0版本

1.1 在pox文件中添加依赖

  <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-boot-starter</artifactId>
          <version>3.0.0</version>
  </dependency>

1.2 访问 http://localhost:8080/swagger-ui/,可能出现下面的问题

image.png
或者
image.png

2.出现上面的情况都是因为spring Security把Swagger需要请求的内容拦截了。需要在SecurityConfig中的configure拦截规则中添加以下代码

.antMatchers("/swagger-ui/**").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/profile/**").anonymous()
.antMatchers("/profile/**").anonymous()
.antMatchers("/v3/**").anonymous()

3. 应该就可以正常的访问了

相关文章

网友评论

      本文标题:SpringBoot集成Security,Swagger遇到的坑

      本文链接:https://www.haomeiwen.com/subject/wwfqdktx.html