问题描述
我有一个spring项目,其中所有端点都在运行https,在尝试运行mvn verify -Dspring.application.admin.enabled=true -Dspring-boot.run.profiles=dev
时会导致以下错误。有没有办法指定证书路径?或通过Spring安全性仅使此端点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>
解决方法
这与您的本地SSL配置有关。这里有一些提示:
-
确保已将证书导入到JDK受托人。
-
JDK信任库应与您的行家使用的相同。
-
在您的CN上,确保您声明localhost。
-
运行maven命令时,请不要忘记添加:
-Djavax.net.ssl.trustStore = / path / to / my-file.jks -Djavax.net.ssl.trustStorePassword = my-pass