使用EclipseLink JPA的SSL

Nit*_*x88 3 java ssl jpa 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>
Run Code Online (Sandbox Code Playgroud)

Mik*_*unu 5

它不是JPA特有的,只是为JDBC连接String添加参数.假设其他所有内容都已正确设置,那么添加它应该足够了:

?useSSL=true&requireSSL=true
Run Code Online (Sandbox Code Playgroud)

如果SSL连接通常不起作用,则此页面提供了更多信息:MySQL 20.3.4.5.使用SSL安全连接