使用swagger2注解需要的依赖
时间: 2023-10-09 13:10:23 浏览: 81
使用Swagger2注解需要添加以下依赖:
```xml
<dependencies>
<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>
</dependencies>
```
这些依赖将允许你在Spring Boot应用程序中使用Swagger2来创建和展示API文档。
相关问题
使用swagger注解需要的依赖
使用Swagger注解需要添加以下依赖:
```xml
<dependencies>
<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>
</dependencies>
```
这些依赖将允许你在Spring Boot应用程序中使用Swagger来创建和展示API文档。
springboot使用swagger2
要在Spring Boot中使用Swagger2,需要进行以下步骤:
1. 在pom.xml文件中添加Swagger2和Swagger UI的依赖:
```xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
```
2. 创建Swagger配置类,用于配置Swagger相关信息:
```java
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo"))
.paths(PathSelectors.any())
.build();
}
}
```
3. 在Controller类中添加Swagger注解,用于描述API接口信息:
```java
@RestController
@RequestMapping("/api")
@Api(tags = "用户管理相关接口")
public class UserController {
@GetMapping("/users")
@ApiOperation("获取所有用户信息")
public List<User> getUsers() {
// ...
}
@PostMapping("/users")
@ApiOperation("创建新用户")
public User createUser(@RequestBody User user) {
// ...
}
}
```
4. 启动Spring Boot应用程序,并访问http://localhost:8080/swagger-ui.html,即可查看API接口文档。