我正在使用以下版本:
spring-boot-starter-parent: 3.3.3
java.version: 21
spring-cloud-version: 2023.0.3
springdoc-openapi-starter-webmvc-ui: 2.6.0
当我运行应用程序并尝试访问 /swagger-ui/index.html 时,我收到 JSON 响应而不是 Swagger UI。
{"name":"swagger-ui","profiles":["index.html"],"label":null,"version":"d2592f45c32657d214294f6b030bef6003d0ee6d","state":null,"propertySources":[]}
这是我的 REST 端点的示例:
@RestController
@RequestMapping("/test/api/web-client")
public class WebClientResource {
@GetMapping("/greet")
public String greet() {
return "Hello World!";
}
}
这里是pom.xml中使用的依赖项
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
将这些添加到您的
application.properties
中,并检查您的应用程序是否在Spring Security下,请在配置中允许如下路径:
http.authorizeRequests()
.antMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
.anyRequest().authenticated();