我添加了swaggerconfig类,如下所示,
@Configuration
@SecurityScheme(
name = "Bearer Authentication",
type = SecuritySchemeType.HTTP,
bearerFormat = "JWT",
scheme = "bearer"
)
public class SwaggerConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().info(new Info().title("Tutor Student API")
.version("1.0.0")
.description("Desc"));
}
在控制器中我添加了这样的内容。
@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/tutors/")
@SecurityRequirement(name = "bearerAuth")
public class tutorController {
@PostMapping(save")
public ResponseEntity<TutorResponse> saveTutor(Authentication authentication,
@Valid @RequestBody(required = true) Tutor tutor, BindingResult bindingResult) {
在这里,经过所有这些变化,我仍然可以提交一个没有承载令牌后的请求,并获得200成功的响应。
1条答案
按热度按时间xuo3flqw1#
在控制器中:
@SecurityRequirement(name = "bearerAuth")
必须命名正确的需求名称:尝试:
@SecurityRequirement(name = "Bearer Authentication")
此致