MySQL spring jpa application.properties 使用SSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35576994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring jpa application.properties useSSL
提问by SJC
I am trying to turn off ssl, to my local mysql database. But I cannot find the actual property in a spring application.properties file that would do this.
我试图关闭 ssl,到我的本地 mysql 数据库。但是我在 spring application.properties 文件中找不到可以执行此操作的实际属性。
my current file is:
我当前的文件是:
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
# Connection url for the database "test"
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Username and password
spring.datasource.username = root
spring.datasource.password = blah
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
I have tried spring.datasource.useSSl=false
and that does not work. I have also tried spring.datasource.url = jdbc:mysql://localhost:3306/test&useSSL=false
我试过了spring.datasource.useSSl=false
,但不起作用。我也试过spring.datasource.url = jdbc:mysql://localhost:3306/test&useSSL=false
回答by Sanjay Mistry
I fixed my issue with the below:
我解决了以下问题:
jdbc:mysql://localhost:3306/test?verifyServerCertificate=false&useSSL=false&requireSSL=false
回答by Subhajit Roy
Shouldn't you be using '?' instead of '&'
你不应该使用'吗?代替 '&'
This is yours
这是你的
spring.datasource.url =jdbc:mysql://localhost:3306/test&useSSL=false
What I'm saying is
我要说的是
spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
回答by gavenkoa
I don't like to pollute java
options or system properties, which are useless in application containers in any case...
我不喜欢污染java
选项或系统属性,它们在任何情况下在应用程序容器中都是无用的......
You can set SSL certificate for MySQL connection programmically with:
您可以使用以下命令以编程方式为 MySQL 连接设置 SSL 证书:
jdbc:mysql://example.com:3306/MYDB?verifyServerCertificate=true&useSSL=true&requireSSL=true&clientCertificateKeyStoreUrl=file:cert/keystore.jks&clientCertificateKeyStorePassword=123456&trustCertificateKeyStoreUrl=file:cert/truststore.jks&trustCertificateKeyStorePassword=123456
jdbc:mysql://example.com:3306/MYDB?verifyServerCertificate=true&useSSL=true&requireSSL=true&clientCertificateKeyStoreUrl=file:cert/keystore.jks&clientCertificateKeyStorePassword=123456&trustCertificateKeyStoreUrl=file:cert/truststore.jificateKeyStoreUrl&
It is documented:
它记录在案: