maven和配置文件
<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>
<!==引出实例属性在配置文件中快速输出==>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
package cn.itcast.swaggerdemo.config;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import springfox.documentation.RequestHandler;
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 {
@Bean
public Docket docket01(){
String groupname="**";
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildapiInfo())
.groupName(groupname)
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("cn.itcast.swaggerdemo.controller"))
.paths(PathSelectors.any())
.build();
}
@Bean
public ApiInfo buildapiInfo(){
Contact contact = new Contact("黑马程序员","www.baidu.com","191022132@qq.com");
return new ApiInfoBuilder()
.title("SwaggerDemo的api文档")
.description("first doing")
.contact(contact)
.version("1.0.0")
.build();
}
@Bean
public Docket docket02(){
String groupname="**";
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildapiInfo1())
.groupName(groupname)
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("cn.itcast.swaggerdemo.controller"))
.paths(PathSelectors.any())
.build();
}
@Bean
public ApiInfo buildapiInfo1(){
Contact contact = new Contact("黑马程序员","","191022132@qq.com");
return new ApiInfoBuilder()
.title("SwaggerDemo的api文档")
.description("first doing")
.contact(contact)
.version("1.0.0")
.build();
}
}
Swagger的访问地址
http://localhost:8080/swagger-ui.html
|