1.在使用SpringBoot開發(fā)項目的過程中同時集成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/,可能出現(xiàn)下面的問題

image.png
或者

image.png
2.出現(xiàn)上面的情況都是因為spring Security把Swagger需要請求的內(nèi)容攔截了。需要在SecurityConfig中的configure攔截規(guī)則中添加以下代碼
.antMatchers("/swagger-ui/**").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/profile/**").anonymous()
.antMatchers("/profile/**").anonymous()
.antMatchers("/v3/**").anonymous()