我正在使用下面的spring boot依赖项。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>我为rest端点配置了Authorization头,如下所示。
@RestController
@Api(tags = "Welcome Controller", description = "Welcome API")
public class HomeController {
@ApiOperation(value = "Sent secret message", notes = "Sent secret message")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Access Token", required = false, allowEmptyValue = false, paramType = "header", dataTypeClass = String.class, example = "Bearer access_token") })
@GetMapping("/secret-message")
public Object tokenResponse() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return principal;
}
}但是,当我打开swagger并尝试执行带有持有者令牌的rest端点时,此Authorizaiton标头不会作为请求的一部分发送。我们该如何解决这个问题呢?
参考https://github.com/tiangolo/fastapi/issues/1037 https://github.com/tiangolo/fastapi/issues/612
发布于 2021-04-24 13:05:16
此问题存在于最新版本的swagger中。但是swagger 2.9.2运行得很好
<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>https://stackoverflow.com/questions/67225923
复制相似问题