如何配置连接池ApacheTomcat->PostgreSQL->PersistenceJava?

如何配置连接池ApacheTomcat->PostgreSQL->PersistenceJava?,java,postgresql,tomcat,jpa,pool,Java,Postgresql,Tomcat,Jpa,Pool,我有一个JavaWeb项目,在ApacheTomcat7服务器上使用Postgresql9.3实现Java8。我正在使用持久性来连接数据库,但我无法配置Apache Tomcat连接池来管理应用程序与数据库的通信量 到目前为止,我在不同的论坛中进行了搜索,在Apache tomcat的context.xhtml文件中找到了以下内容: <Resource name="jdbc/ead" auth="Container" type="javax.sql.DataSource" maxTotal

我有一个JavaWeb项目,在ApacheTomcat7服务器上使用Postgresql9.3实现Java8。我正在使用持久性来连接数据库,但我无法配置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"/>
<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>
在web项目的web.xml文件中添加以下行:

<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"/>
<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文件中,以便在使用由persistence生成的JPA控制器时,使用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>
尝试:


顺便说一句,请查看该网站:“PostgreSQL 9.3现在已经过时,将不再收到任何错误或安全修复。我们敦促用户尽快开始计划升级到PostgreSQL的更高版本。”感谢您的澄清,但这并不取决于我。系统必须适应几年前已经定义的环境,我不是原始软件的所有者。我的软件是其他软件的模块,将安装在具有相同环境的同一服务器上。我必须使用相同的环境来避免产生冲突,这个软件正在工作。我解决了问题,你给我的想法很有效。但除此之外,我还有一个写得很糟糕的密码。在context.xml文件中,单词resources拼写错误,必须编写的是resource。由于在运行服务器时,日志中出现了一系列错误,无法找到标记name、auth等。但我已经解决了问题,感谢您的帮助。