springboot中swagger怎么修改路径
时间: 2023-09-16 21:01:43 浏览: 164
在Spring Boot中使用Swagger生成API文档时,我们可以通过修改配置来修改路径。
1. 首先,在pom.xml文件中,确保已经添加了Swagger的依赖包。例如:
```java
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.10.5</version>
</dependency>
```
2. 在Spring Boot的配置文件(如application.properties或application.yml)中,可以使用以下属性来修改Swagger的路径:
```java
# Swagger路径配置
# 修改Swagger API文档的访问路径,默认是 /v2/api-docs
springfox.documentation.swagger.v2.path=/myapi/swagger
# 修改Swagger UI的访问路径,默认是 /swagger-ui.html
springfox.documentation.swagger-ui.path=/myapi/swagger-ui.html
```
通过以上配置,我们可以将Swagger API文档的访问路径修改为 `/myapi/swagger`,将Swagger UI的访问路径修改为 `/myapi/swagger-ui.html`。
3. 启动Spring Boot应用后,访问修改后的路径即可查看、测试API文档。
总结一下,通过在配置文件中添加 `springfox.documentation.swagger.v2.path` 和 `springfox.documentation.swagger-ui.path` 属性,我们可以轻松地修改Swagger的路径。
阅读全文
相关推荐


















