在我的项目中,我需要为所有@RestController bean映射添加前缀。因此,我添加了这个config类:
@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-启动-启动器-父=> 2.3.12
springdoc data-rest&springdoc ui => 1.5.9
发布于 2021-09-19 06:08:17
这是该版本中的一个错误(不支持HandlerTypePredicate)。
看我的封闭性问题:
https://github.com/springdoc/springdoc-openapi/issues/1258#issuecomment-922325290
https://stackoverflow.com/questions/68599162
复制相似问题