pom.xml
io.springfox springfox-swagger22.9.2 spring-context org.springframework spring-aop org.springframework spring-beans org.springframework io.springfox springfox-swagger-ui2.9.2 com.github.xiaoymin swagger-bootstrap-ui1.9.3
java
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(documentationType.SWAGGER_2)
.enable(true)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.*"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.description("Spring Boot中使用Swagger2构建RESTful APIs")
.version("1.0")
.build();
}
}
application.yml
swagger:
ui-config:
# method<按方法定义顺序排序>
operations-sorter: method
basic:
enable: true
## Basic认证用户名
username: admin
## Basic认证密码
password: admin
访问地址:
http://ip:port/doc.html
http://ip:port/工程名/doc.html
http://ip:portswagger-ui.html
http://ip:port/工程名/swagger-ui.html



