我在SpringMVC应用程序中使用springfox-swagger2。我可以访问/ v2 / api-docs并获取JSON格式的结果,但是即使已经使用@Api和@ApiOperation也看不到任何api。看来Swagger无法扫描注释
春季:3.2.x 昂首阔步:2.6.1
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
SwaggerConfig.class:
@Configuration
@EnableSwagger2
@ComponentScan(basePackages = {"com.xxxxxxxxx"})
public class SwaggerConfig
{
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("MyGroup")
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("")
.description("")
.termsOfServiceUrl("")
.version("1.0.0")
.build();
}
spring-mvc.xml:
<bean class="com.mypackage.SwaggerConfig" />
和我的考试班
@Api(tags = "hello world")
public class Hello {
@ApiOperation(value = "hello")
void f() {}
}
和运行时环境 雄猫
WEB-INF
|
|--classes
|----SwaggerConfig.class
|----Hello.class
http://localhost:8080/v2/api-docs?group=MyGroup 并得到这样的结果
{
"swagger": "2.0",
"info": {
"description": " this is description",
"version": "1.0.0",
"title": " this is title ",
"termsOfService": " this is terms of service"
},
"host": "localhost",
"basePath": "/"
}
apis列表为空?? !!