java - 使用 EclipseLink JPA 的 SSL

标签 java jpa ssl eclipselink

是否可以使 JPA 对其连接使用 SSL。我不太了解 JPA,因此我无法提供有关我使用的版本和提供程序的许多详细信息,但这是我的 persistence.xml 文件的剥离版本。您是否可以添加使其使用安全连接的属性?

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="MY_PERSISTENCE_UNIT" transaction-type="RESOURCE_LOCAL">
    <!-- declare class entities here -->

    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://URL_TO_SERVER" />
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="USERNAME" />
        <property name="javax.persistence.jdbc.password" value="PASSWORD" />

        <!-- Optimize database writes to use batching. -->
        <property name="eclipselink.jdbc.batch-writing" value="JDBC" />

        <!-- Avoids flush being triggered before every query execution. -->
        <property name="eclipselink.persistence-context.flush-mode"
            value="COMMIT" />

        <!-- Configure connection pool. -->
        <property name="eclipselink.jdbc.connections.initial" value="1" />
        <property name="eclipselink.jdbc.connections.min" value="64" />
        <property name="eclipselink.jdbc.connections.max" value="64" />

        <!-- Timeout for connection. -->
        <property name="eclipselink.jdbc.timeout" value="10" />

        <!-- Configure cache size. -->
        <property name="eclipselink.cache.size.default" value="1000" />

        <!-- Configure database to be created on startup if not already existing.-->
        <property name="eclipselink.ddl-generation" value="create-tables" />

        <!-- Configure simple SQL logging for demonstration. -->
        <property name="eclipselink.logging.level" value="FINE" />
        <property name="eclipselink.logging.thread" value="false" />
        <property name="eclipselink.logging.session" value="false" />
        <property name="eclipselink.logging.exceptions" value="false" />
        <property name="eclipselink.logging.timestamp" value="false" />
    </properties>
</persistence-unit>

最佳答案

这不是 JPA 特定的,只是将参数添加到 JDBC 连接字符串。假设其他一切都已正确设置,那么添加这个就足够了:

?useSSL=true&requireSSL=true

如果 SSL 连接一般不工作,则此页面提供更多信息:MySQL 20.3.4.5. Connecting Securely Using SSL

关于java - 使用 EclipseLink JPA 的 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8336660/

相关文章:

ruby-on-rails - 在 Rails 中设计不适用于 HTTPs

Sharepoint SSL Web.Config 访问问题

java - 在java中反转并打印单链表

java - 不同风格的程序流程?

java - 持久化没有 ID 的第三方类

json - 使用 Spring/JPA 写入 Postgres 数据库的 JSON 列

java - 编写测试用例时将 Json 响应转换为 java 对象时出错

java - 如何从 java 中使用 Crossover 启动命令行应用程序?

hibernate - 如何使用 spring boot 1.5.x 配置 "hibernate.integrator_provider"

ssl - TLS 如何安全地协商共享 key ?