我想在 springboot 2 上创建一个 swagger 配置。我在 PON 文件中添加了正确的依赖项。但我仍然无法导入所需的导入。
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-bean-validators -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
尝试重新加载整个项目,然后全新安装,并验证库是否已下载。
如果这不起作用,请尝试此依赖项:(使用 Springboot 2.3.2 进行测试)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>-->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.8.0</version>
</dependency>
请记住,这确实很旧,可能不再受支持
最好的解决方案是使用 openApi (使用 springboot 2.7 进行测试):
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
也将其添加到您的属性中:
springdoc.packages-to-scan=de.xqueue.txe.api.controllers
springdoc.api-docs.enabled=true
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tryItOutEnabled=true
springdoc.swagger-ui.filter=false
springdoc.swagger-ui.tagsSorter=alpha
springdoc.swagger-ui.validatorUrl=none
springdoc.swagger-ui.defaultModelRendering=model
springdoc.swagger-ui.docExpansion=full