如何配置连接池的Apache Tomcat-> PostgreSQL->持久性的Java?

问题描述 投票:0回答:1

我有Java8一个Apache服务器Tomcat7使用Postgresql9.3一个Java Web项目。我使用的持久性连接到数据库,但我不能配置的Apache Tomcat连接池管理与数据库的应用程序的流量。

到目前为止,我已搜查在不同的论坛和我所发现的是Apache Tomcat上的context.xhtml文件中添加这些行:

<Resource name="jdbc/ead" auth="Container" type="javax.sql.DataSource" maxTotal="100" maxIdle="30" maxWaitMillis="10000" username="postgres" password="postgres" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/SIGENU_EaD"/>

在Web项目的web.xml文件中添加这些行:

<resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/ead</res-ref-name>
        <res-type>org.postgresql.Driver</res-type>
        <res-auth>Container</res-auth>
</resource-ref>

我的问题是如何将这种配置添加到persistence.xml文件,以便使用持久性所产生的JpaControllers时,使用的Apache Tomcat池,而不是直接连接。

目前persistence.xml文件看起来是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="dist_educ_finalPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>entity.EstadoCivil</class>
        <class>entity.ProcedenciaEscolar</class>
        <class>entity.Disciplina</class>
        <class>entity.Planestudio</class>
        <class>entity.FuenteIngreso</class>
        <class>entity.TipoAsignatura</class>
        <class>entity.Especialidad</class>
        <class>entity.MatriculaEstudianteAsignatura</class>
        <class>entity.Organismo</class>
        <class>entity.Asignatura</class>
        <class>entity.Huerfano</class>
        <class>entity.Tutor</class>
        <class>entity.ColorPiel</class>
        <class>entity.GradoMilitar</class>
        <class>entity.EspecialidadMilitar</class>
        <class>entity.Authorities</class>
        <class>entity.Ocupacion</class>
        <class>entity.Carreranacional</class>
        <class>entity.Minusvalia</class>
        <class>entity.Estudiante</class>
        <class>entity.Sexo</class>
        <class>entity.NivelEscolar</class>
        <class>entity.Users</class>
        <class>entity.Universidad</class>
        <class>entity.OrganizacionPolitica</class>
        <class>entity.OrganizacionPopular</class>
        <class>entity.Municipio</class>
        <class>entity.TipoEvaluacion</class>
        <class>entity.Examen</class>
        <class>entity.Matricula</class>
        <class>entity.MatriculaEstudianteAsignaturaExamen</class>
        <class>entity.Pais</class>
        <class>entity.Centrotrabajo</class>
        <class>entity.EstadoEstudiante</class>
        <class>entity.Curso</class>
        <class>entity.Provincia</class>
        <class>entity.Ong</class>
        <class>entity.Sindicato</class>
        <class>entity.Area</class>
        <class>entity.Carrera</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/SIGENU_EaD"/>
            <property name="javax.persistence.jdbc.user" value="postgres"/>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name="javax.persistence.jdbc.password" value="postgres"/>
        </properties>
    </persistence-unit>
</persistence>
java postgresql tomcat jpa pool
1个回答
1
投票

尝试:

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="dist_educ_finalPU" transaction-type="RESOURCE_LOCAL">   
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <non-jta-data-source>java:comp/env/jdbc/ead</non-jta-data-source>
    ...
  </persistence-unit>
<persistence>
© www.soinside.com 2019 - 2024. All rights reserved.