Spring Boot使用SSL证书连接数据库

Jig*_*aik 3 postgresql ssl-certificate spring-boot

我需要使用 Spring Boot 应用程序中的 SSL 证书连接到 postgresql。我已经获得了证书,目前我正在使用我在 application.yml 文件中提供的用户名和密码连接到数据库。

有人可以指出我正确的教程吗?我找不到与 spring boot ssl 数据库连接相关的任何内容。

Sha*_*dra 5

您需要在 URL 中附加以下内容

&sslmode=verify-full&sslrootcert=/path/to/pemfile
Run Code Online (Sandbox Code Playgroud)

您的网址将类似于

jdbc:postgresql://server:5432/databaseName?currentSchema=dbschema
    &sslmode=verify-full&sslrootcert=/home/certificates/mycert.pem
Run Code Online (Sandbox Code Playgroud)

你可以参考下面的网址

https://jdbc.postgresql.org/documentation/head/connect.html#ssl

https://docs.amazonaws.cn/en_us/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.SSL