有没有可能让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>
发布于 2011-12-01 20:21:22
它不是特定于JPA的,只是将参数添加到JDBC连接字符串。假设所有其他内容都已正确设置,则添加以下内容就足够了:
?useSSL=true&requireSSL=true如果SSL连接一般不工作,则此页面提供更多信息:MySQL 20.3.4.5. Connecting Securely Using SSL
发布于 2018-02-09 04:41:18
我发现在JDBC2.5.0中将属性传递给EclipseLink驱动程序非常有用:
<property name="eclipselink.jdbc.property.my_property_name" value="my_value" />这是特定于驱动程序的,但在您的示例中是:
<property name="eclipselink.jdbc.property.useSSL" value="true" />
<property name="eclipselink.jdbc.property.requireSSL" value="true" />https://stackoverflow.com/questions/8336660
复制相似问题