我有几个具有相同请求路径前缀的控制器,即
/v4/users/{userId}/
然后控制器中的方法使用单独的路径映射进行注释。 swagger ui只显示其中一个控制器。
@Component
public class BaseController {
}
/******************/
@RestController
@RequestMapping("/v4/users/{userId}/payment")
public class PaymentController extends BaseController {
@RequestMapping(value = "/initiate", method = RequestMethod.POST)
public HttpEntity<Object> initiatePayment() {...}
@RequestMapping(value = "/success", method = RequestMethod.GET)
public HttpEntity<Object> success() {...}
}
@RestController
@RequestMapping("/v4/users/{userId}/preferences")
public class CustomerPreferencesController extends BaseController{
@RequestMapping(value = "/deals/{dealId}", method = RequestMethod.POST)
public HttpEntity<Object> favouriteDeal(...) {...}
//some more methods
}
还有一个控制器具有相同的路径前缀,即 / v4 / users / {userId} ,它出现在swagger-ui上,而不是上面两个控制器。
pom.xml 条目:
<!-- Swagger Spring -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.0.2</version>
</dependency>
更新 - 1
@Bean
public Docket mobileAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.host(swaggerHost)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.pathMapping("/");
}