【发布时间】:2021-10-06 11:35:34
【问题描述】:
在我的项目中,我需要为所有 @RestController beans 映射添加前缀。所以我添加了这个配置类:
@Configuration
public class AppConfiguration implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.addPathPrefix("/rest",
HandlerTypePredicate.forAnnotation(RestController.class));
}
}
之后我看到 swagger 无法使用默认地址正确预览,所以我添加了这个配置键:
springdoc.swagger-ui.path= swagger
springdoc.swagger-ui.url= /rest/api-docs
现在我看到这个页面有正确的控制器映射但是当我尝试它时,url 再次添加前缀并将地址更改为 /rest/rest/...
@RestController
public class WorkflowController {
private final WorkflowService workflowService;
private final Environment environment;
public WorkflowController(WorkflowService workflowService, Environment environment) {
this.workflowService = workflowService;
this.environment = environment;
}
@PostMapping(value = "/phoneCharge")
public GeneralResponse startChargeProcess(@Valid @RequestBody MerchantChargeRequestDto dto, HttpServletRequest request) {
return workflowService.startChargeProcess(dto, request.getRemoteAddr(), "ChargeProcess");
}
}
怎么了?
我用这个版本
spring-boot-starter-parent => 2.3.12.RELEASE
springdoc-openapi-data-rest & springdoc-openapi-ui => 1.5.9
【问题讨论】:
标签: spring-boot swagger-ui springdoc