在SpringBoot中配置swagger
1、首先在pom包中加入swagger的依賴
<!-- swagger2 -->
<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>
2、在配置包中創建SwaggerConfig類
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API")
.description("展示先做基礎功能,後面再添加業務")
.version("1.0")
.build();
}
}
在配置類中我只是加了一些基礎的屬性,具體的屬性可以自己再加入!
3、配置啓動類
@SpringBootApplication
@EnableSwagger2
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
加入相應的註解。
啓動項目,然後訪問http://localhost:8080/swagger-ui.html#/