1.环境
SpringBoot 2.0.4.RELEASE
Swagger 1.7.1
JDK 1.8
2.依赖
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.1.RELEASE</version>
</dependency>
3.Swagger配置Bean
@Configuration会被项目启动加载为配置类,等同于XML中配置的beans;
@Bean标注方法等同于XML中配置的bean。
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xx.xx.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return n