Configure spring to connect to mysql over ssl

后端 未结 3 1609
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 14:53

I am connecting to MySQL over SSL from my Java application. I have configured MYSQL to support SSL and generated client certificates. I have imported server CA certificate a

3条回答
  •  借酒劲吻你
    2020-12-31 15:59

    The value for jdbc.url in jdbc.properties has to be

    jdbc:mysql://127.0.0.1:3306/MySampleDb?verifyServerCertificate=true&useSSL=true&requireSSL=true

    Those parameters must be added directly to the URL for MySQL. The parameters for keyStore and trustStore should be passed to the JVM at start like so:

    -Djavax.net.ssl.keyStore=path_to_keystore_file
    -Djavax.net.ssl.keyStorePassword=password
    -Djavax.net.ssl.trustStore=path_to_truststore_file
    -Djavax.net.ssl.trustStorePassword=password
    

    You can use Spring to set system properties but I'd never use it, it's too cumbersome.

提交回复
热议问题