spring boot 集成swagger3
时间: 2023-10-24 18:05:35 浏览: 211
好的,关于集成Swagger3,你可以按照以下步骤进行操作:
1. 在pom.xml文件中添加Swagger3的依赖:
```xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
```
2. 在Spring Boot的启动类上添加`@EnableSwagger2`注解:
```java
@SpringBootApplication
@EnableSwagger2
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
3. 创建Swagger配置类,配置Swagger相关信息:
```java
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot集成Swagger3")
.description("Spring Boot集成Swagger3示例")
.version("1.0")
.build();
}
}
```
4. 启动应用程序,访问`http://localhost:8080/swagger-ui/index.html`即可查看API文档。
阅读全文
相关推荐


















