Spring Boot 2.6.3 与 Springdoc。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在 中applicaton.yaml,当我将路径设置为 /v3/api-docs 或将其删除时,这意味着使用默认路径“/v3/api-docs”。Swagger UI 页面使用 API http://localhost:8080/swagger-ui/index.html 正确显示
但我想重写路径如下
api-docs.path: /bus/v3/api-docs
Run Code Online (Sandbox Code Playgroud)
然后 Swagger UI 显示“无法加载远程配置”错误:

我正在尝试使用 Spring Boot 2.6.7 运行 Springdoc。
配置:
@Configuration
public class SwaggerConfiguration {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("springshop-public")
.pathsToMatch("/public/**")
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
错误堆栈:
00:50:54.956 [main] ERROR SpringApplication[reportFailure:830] - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.atlas.psp.AtlasRouterApplication.main(AtlasRouterApplication.java:53) …Run Code Online (Sandbox Code Playgroud) 带有 springdoc-openapi-ui (Swagger UI) 的 Spring Boot 2.2 应用程序运行 HTTP 端口。该应用程序部署到 Kubernetes,并通过 Ingress 将 HTTPS 请求从集群外部路由到服务。
在这种情况下,可用的 Swagger UIhttps://example.com/api/swagger-ui.html有错误的“生成的服务器 url”- http://example.com/api。虽然应该如此https://example.com/api。
虽然 Swagger UI 通过 HTTPS 访问,但生成的服务器 URL 仍然使用 HTTP。
Swagger2 (springfox) 合作过:
@Bean
public Docket getDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false)
.globalOperationParameters(Collections.singletonList(getAuthHeader()));
}
private Parameter getAuthHeader() {
return new ParameterBuilder()
.parameterType("header")
.name("Authorization")
.modelRef(new ModelRef("string"))
.defaultValue(getBase64EncodedCredentials())
.build();
}
private String getBase64EncodedCredentials() {
String auth = authUser.getUser() + ":" + authUser.getPassword();
byte[] encodedAuth = Base64.encode(auth.getBytes(StandardCharsets.UTF_8));
return "Basic " + new String(encodedAuth, Charset.defaultCharset());
}
Run Code Online (Sandbox Code Playgroud)
Springdoc-openapi:
@Bean
public OpenAPI getOpenAPI() {
return new OpenAPI().components(new Components()
.addHeaders("Authorization", new Header().description("Auth header").schema(new StringSchema()._default(getBase64EncodedCredentials()))));
}
Run Code Online (Sandbox Code Playgroud)
我无法为 springdoc-openapi 实现它。看来标题不起作用。
我正在使用 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,不确定问题出在哪里,项目无法运行。
我正在使用SpringDoc 1.4.3招摇。
我添加了以下配置以禁用中的petstoreURLapplication.yml
配置
springdoc:
swagger-ui:
disable-swagger-default-url: true
tags-sorter: alpha
operations-sorter: alpha
doc-expansion: none
Run Code Online (Sandbox Code Playgroud)
但是当我在探索文本框中点击https://petstore.swagger.io/v2/swagger.json时,它仍然显示如下图所示的 petsore URL。
招摇形象
swagger-ui openapi springdoc springdoc-ui springdoc-openapi-ui
有两种方法可以将 OpenAPI 3 添加到 Spring Boot 项目。
\n<groupId>org.springdoc</groupId>\n<artifactId>springdoc-openapi-ui</artifactId>\nRun Code Online (Sandbox Code Playgroud)\nhttps://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/
\n<groupId>io.springfox</groupId>\n<artifactId>springfox-boot-starter</artifactId>\nRun Code Online (Sandbox Code Playgroud)\nhttps://medium.com/@hala3k/setting-up-swagger-3-with-spring-boot-2-a7c1c3151545
\n还有配置和注释的迁移问题。
\n问题是:对于 Spring Boot 项目,有什么理由在它们之间做出选择吗?
\n更新:迁移到 OpenAPI 3。不太难:)也许会有帮助:
\nOpenApiConfig ,\n pom.xml ,\n \xd0\x9e\xd0\xbf\xd0\xb8\xd1\x81\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb5
\n需要 springdoc-openapi-ui 的一些帮助!
我正在使用 springdoc-openapi-ui 来呈现我的 API 模式。这是它的版本详细信息。
现在,我已经在我的 Spring Boot 应用程序中完成了一些配置,如下所示

现在,我期望当我点击 时localhost:15041/swagger-ui.html,它应该默认带我http://localhost:15041/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config到此并呈现我的 API 文档,但不幸的是它只呈现 Petstore。即使我直接转到http://localhost:15041/swagger-ui.html?configUrl=/v3/api-docs/swagger-config,它也不会使用 swagger-config 进行渲染。

虽然如果我去localhost:15041/v3/api-docs我会得到我的 json API 文档localhost:15041/v3/api-docs/swagger-config,并且我会得到 swagger-config。另外,如果我进入/v3/api-docspetstore 页面的 Explore 搜索区域,它会显示我的 API 文档。
我花了超过 1.5 天的时间来修复它,但它不起作用。如果有人可以提供帮助,我真的很感激。
mvn clean install 出现错误,尝试为 openAPI 规范生成 openapi.json
[错误] 无法在项目 abcd 上执行目标 org.springframework.boot:spring-boot-maven-plugin:2.3.0.RELEASE:start (pre-integration-test):无法确定应用程序是否已启动:无法连接到端口 9001 处的 MBean 服务器:无法调用关闭操作:Spring 应用程序在配置的超时之前未启动(30000 毫秒 -> [帮助 1] [错误] [错误] 要查看错误的完整堆栈跟踪,请重新-使用 -e 开关运行 Maven。[错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。[错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
使用以下配置 -
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.4</version>
</dependency>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
<outputFileName>openapi.json</outputFileName>
<outputDir>${project.build.directory}</outputDir>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass></mainClass>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals> …Run Code Online (Sandbox Code Playgroud) spring-boot ×7
swagger-ui ×7
java ×5
springdoc ×5
swagger ×4
openapi ×2
maven ×1
springdoc-ui ×1
springfox ×1