pom中添加依赖
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
xml配置文件中添加扫描
<!-- 2、开启组件扫描 -->
<context:component-scan base-package="com.t3.swagger"/>
新建SwaggerConfig工具类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(true) // 是否禁用swagger
.useDefaultResponseMessages(false)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("swagger API文档")
.description("Dcpnet商品管理系统接口文档")
.version("1.0")
.build();
}
}
在Controller类前添加@API注解
@Api(value = "AdminController管理",tags = "AdminController管理接口API")
启动服务器,浏览器输入
http://localhost:8080/XXX/swagger-ui.html