java - 由于 PropertySourcedMapping,覆盖 swagger 2 api-docs 不会导致我的控制器被调用
问题描述
我试图用我自己的控制器覆盖 api-docs 端点,这似乎不起作用。
我已在 application.properties 中设置
springfox.documentation.swagger.v2.path=/somethingelse
然后我制作了自己的控制器
@RequestMapping(
value = "/v2/api-docs",
method = RequestMethod.GET,
produces = { APPLICATION_JSON_VALUE, "application/hal+json" })
这是试图覆盖由Swagger2Controller
which 给出的响应,如下所示:
@RequestMapping(
value = DEFAULT_URL, // /v2/api-docs
method = RequestMethod.GET,
produces = { APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE })
@PropertySourcedMapping(
value = "${springfox.documentation.swagger.v2.path}",
propertyKey = "springfox.documentation.swagger.v2.path")
@ResponseBody
public ResponseEntity<Json> getDocumentation(
@RequestParam(value = "group", required = false) String swaggerGroup,
HttpServletRequest servletRequest) {
由于某种原因,请求仍将发送到该控制器而不是我的控制器。
奇怪的是,如果我的控制器不存在请求/v2/api-docs
不会响应。
春狐:2.9.2 春:5.1.4
解决方案
A 类扩展Swagger2DocumentationConfiguration
覆盖
public HandlerMapping swagger2ControllerMapping(Environment environment, DocumentationCache documentationCache,
ServiceModelToSwagger2Mapper mapper, JsonSerializer jsonSerializer) {
return new PropertySourcedRequestMappingHandlerMapping(
environment,
new CustomSwagger2Controller(environment, documentationCache, mapper, jsonSerializer));
}
CustomSwagger2Controller是我的自定义控制器
推荐阅读
- python - python异步图像下载(多个网址)
- scala - 为什么scala复制不保留原始类实例的状态?
- amazon-web-services - 尝试查找 AWS WAF 区域的 ARN 模式
- c - While循环的行为不同,而条件相同?
- json - 将 JSON 数组扩展为具有 NULL 的文本值
- php - 调用php文件后如何响应?
- html - 如何在将指针移开时使用 CSS 使文本单独消失
- r - 将 ggplot 图形导出为 pdf 时出错:字体类型无效
- java - 如何使用字符串变量
- python - 如何让 Google Assistant 使用 Python 脚本从网络获取数据