我成功使用MySQL Workbench对Bluemix托管的MySQL Compose服务进行了全面的测试。
然后我在本地笔记本电脑上用Apache Derby构建了一个带有SpringBoot的简单微服务......成功。
我的下一步是使用Bluemix中托管的MySQL Compose。
我编辑了application.properties并遇到了这个错误 " PKIX路径构建失败:...." " SunCertPathBuilderException:无法找到有效的证书路径来请求目标"
application.properties file
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.datasource.url=jdbc:mysql://somedomain:port/compose?useSSL=true?requireSSL=true
spring.datasource.username=myname
spring.datasource.password=mypassword
Bluemix在json中为我提供了这些凭据:
{
"db_type": "mysql",
"name": "bmix-dal-yp-xxxxxxx-",
"uri_cli": "mysql -u myname -p --host somedomain.com --port 5555 --ssl-mode=REQUIRED",
"ca_certificate_base64": "LS0tLS1CRUd......",
"deployment_id": "58fexxxxxxxxxxx",
"uri": "mysql://myname:mypassword@somedomain.com:55555/compose"
}
我应该在我的application.properties中使用ca证书吗?
我是否需要在我的嵌入式tomcat服务器上启用ssl,默认情况下使用springBoot运行?
如何配置我的springBoot应用程序以连接到我的云提供程序MySQL实例使用SSL并使用它们提供的json?
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
答案 0 :(得分:1)
将以下内容添加到您的pom.xml(或等效文件):
env:
# Add the certificate from VCAP_SERVICES ca_certificate_base64
# You need to base64 decode the certificate and add it below
# E.g. echo '<<ca_certificate_base64>>' | base64 -D
TRUSTED_CA_CERTIFICATE: |-
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
将以下内容添加到manifest.yml
cf set-env <app> JAVA_OPTS '-Djavax.net.ssl.TrustStore=classpath:resources/config/truststore -Djavax.net.ssl.trustStorePassword=changeit'
有关详细信息,请参阅https://github.com/orange-cloudfoundry/spring-boot-ssl-truststore-gen
另请参阅此处的最小应用:https://github.com/snowch/hello-spring-cloud/tree/8b9728a826dcc1995a7ccb19a852ac8face21147
这是我的第一个答案 - 这不起作用。忽略此部分。
一个选项是:
将证书导入Java truststore文件,将文件打包为Java 应用程序并通过JAVA_OPTS环境变量指定其路径; truststore文件可以放在资源目录下。这个可以 用于单一应用:
使用'cf set-env'命令:
applications: - name: java-app ... env: JAVA_OPTS: '-Djavax.net.ssl.TrustStore=classpath:resources/config/truststore -Djavax.net.ssl.trustStorePassword=changeit'
或者,使用manifest.yml
ca_certificate_base64
请注意,字段echo '<<ca_certificate_base64>>' | base64 -D > ca_certificate.pem
中的证书是base64编码的,因此您需要在将其添加到信任库之前对其进行解码,例如
解码证书:
keytool -import -trustcacerts -file ca_certificate.pem -alias compose_cert -keystore resources/config/truststore -storepass changeit -noprompt
创建信任库:
{{1}}
请注意,密钥库位置(resources / config / truststore)和storepass(changeit)是在JAVA_OPTS中设置的。
您可以尝试一些不同的选项。有关详细信息,请参阅此文档:https://discuss.pivotal.io/hc/en-us/articles/223454928-How-to-tell-application-containers-running-Java-apps-to-trust-self-signed-certs-or-a-private-or-internal-CA