首页 > 解决方案 > 如何通过 HTTPS 使用 springdoc-openapi-maven-plugin

问题描述

我有一个 spring 项目,其中所有端点都在运行 https ,这在尝试运行时会导致以下错误mvn verify -Dspring.application.admin.enabled=true -Dspring-boot.run.profiles=dev。有没有办法指定证书路径?或仅使用弹簧安全性使此端点 http 而不是 https 的方法。

错误:

[ERROR] An error has occurred
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path 
building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find 
valid certification path to requested target

Pom.xml

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.3.0.RELEASE</version>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <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>https://localhost:8444/v3/api-docs</apiDocsUrl>
            </configuration>
        </plugin>

标签: spring-bootmavenopenapispringdoc

解决方案


这与您的本地 SSL 配置有关。以下是一些提示:

  • 确保您已将证书导入到您的 JDK 信任库。

  • JDK 信任库应该与您的 Maven 使用的相同。

  • 在你的 CN 上,确保你声明了 localhost。

  • 运行 maven 命令时不要忘记添加:

    -Djavax.net.ssl.trustStore=/path/to/my-file.jks -Djavax.net.ssl.trustStorePassword=my-pass


推荐阅读