接上篇《Apache Shiro 接管Swagger认证授权》,有热心网友反应Apache Shiro似乎太简单。针对这个问题,个人不做任何评价(一切技术服务于需求)。今天主要分享内容为:在Spring Security下如何接管Swagger的认证授权工作。
1.添加依赖
假定你对Swagger和Spring Security已经有一定的基础,现在开始检查你的项目中是否添加了Swagger和Spring Security的依赖。以Maven为例,向pom.xml文件添加如下配置信息:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<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>
2.配置Swagger
Swagger的配置相对比较简单,最主要的是配置其扫描的包路径,其他信息可以选配。你可以按照下列方式进行配置:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration