Bab*_*sht 10 java swagger swagger-ui spring-boot springdoc-openapi-ui
我正在使用 springdoc-openapi-ui 作为 Spring Boot API 文档并面临以下问题 -
我已添加所有必要的配置,如下 -
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
package com.abc.tl;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@OpenAPIDefinition
public class TLApplication {
public static void main(String[] args) {
SpringApplication.run(TLApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
使用java版本 - 11,不确定问题出在哪里,项目无法运行。
Deb*_*ash 12
通过以下依赖关系,解决了这个问题。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.12</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
小智 12
我在我的应用程序 application.properties 中添加了以下对我有用的行。
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Run Code Online (Sandbox Code Playgroud)
似乎PathPatternParser
不允许**
出现在中间,并且会拒绝这样的模式(请参阅更多详细信息: https: //github.com/spring-projects/spring-boot/issues/21694)。
看起来这里的代码**
在路径模式的中间插入了一个。
uiRootPath.append(ALL_PATTERN);
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PATTERN)
Run Code Online (Sandbox Code Playgroud)
完整代码
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
StringBuilder uiRootPath = new StringBuilder();
if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
uiRootPath.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort())
uiRootPath.append(actuatorProvider.get().getBasePath());
uiRootPath.append(ALL_PATTERN);
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PATTERN)
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
.resourceChain(false)
.addTransformer(swaggerIndexTransformer);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29040 次 |
最近记录: |