pom.xml添加依赖
<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>
新增config包,config包中新增SwaggerConfig.java
package org.example.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private static Logger log = LoggerFactory.getLogger(SwaggerConfig.class);
@Bean
public Docket createRestApi() {
log.info("进入到swagger的配置中");
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("groupxx")
.select()
.apis(RequestHandlerSelectors.basePackage("org.example.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot集成Swagger2接口总览")
.description("Swagger接口")
.contact(new Contact("测试swagger","http://localhost:8080/",""))
.version("1.0")
.build();
}
}
输入http://localhost:8008/swagger-ui.html