这是我的配置文件:
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket api() {
Docket result = new Docket(
DocumentationType.SWAGGER_2).select().apis(
RequestHandlerSelectors.any()).paths(
PathSelectors.any()).build();
return result;
}
}
和:
@Configuration
@EnableWebMvc
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(
"swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler(
"/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
}
这是我有一个简单的控制器:
@RestController
@RequestMapping("/")
public class TestingController extends AbstractController {
@RequestMapping(value = "/play", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public ResponseDTO foo(@RequestBody RequestDTO requestDTO) throws IOException {
return this.myService.exec(requestDTO);
}
由于某种原因,网址:
http://localhost:8080/app/v2/api-docs
给了我以下内容:
{"swagger":"2.0","info":{"description":"Api Documentation","version":"1.0","title":"Api Documentation","termsOfService":"urn:tos","contact":{},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}},"host":"localhost:8080","basePath":"/app"}
我有很多控制器和方法,为什么没有显示出来?PS - 的
Docket result = ...
似乎没有返回任何路径\路线,为什么?