当尝试加载 http://localhost:8080/swagger-ui/index.html 时,我将收到一个带有以下输出的错误控制台:
swagger-ui-bundle.js:2 Uncaught SyntaxError: Invalid or unexpected token (at swagger-ui-bundle.js:2:537471)
swagger-ui-standalone-preset.js:2 Uncaught SyntaxError: Invalid or unexpected token (at swagger-ui-standalone-preset.js:2:147026)
swagger-initializer.js:5 Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload (swagger-initializer.js:5:3)
window.onload @ swagger-initializer.js:5
load (async)
(anonymous) @ swagger-initializer.js:1
有人有想法吗?
我的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
**<version>3.1.6</version>**
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- SWAGGER -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
**<version>2.0.0</version>**
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
我尝试加载其他版本,但似乎没有任何帮助。尝试更改插件,因为我怀疑这可能是一个问题
尝试使用此版本进行测试:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version> <!--- old version from 2021 -->
</dependency>
还要确保您的 application.properties 正确:
## Swagger-ui & Documentation
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