JPA在JSF项目中未找到适合JDBC PostgreSQL的驱动程序

JPA在JSF项目中未找到适合JDBC PostgreSQL的驱动程序,jpa,glassfish,connection,eclipselink,pool,Jpa,Glassfish,Connection,Eclipselink,Pool,我正在Maven的JSF项目中使用JPA(EclipseLink)。在运行时引发以下异常:未找到适合jdbc的驱动程序:postgresql://localhost:5432/project 之后,必须重新启动GlassFish服务器 Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: No suitable driver f

我正在Maven的JSF项目中使用JPA(EclipseLink)。在运行时引发以下异常:
未找到适合jdbc的驱动程序:postgresql://localhost:5432/project

之后,必须重新启动GlassFish服务器

Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: No suitable driver found for jdbc:postgresql://localhost:5432/project?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false&binaryTransfer=true
    at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:103)
    at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944)
    at com.sun.enterprise.resource.pool.ConnectionPool.resizePoolAndGetNewResource(ConnectionPool.java:792)
    at com.sun.enterprise.resource.pool.ConnectionPool.getResourceFromPool(ConnectionPool.java:760)
    at com.sun.enterprise.resource.pool.ConnectionPool.getUnenlistedResource(ConnectionPool.java:632)
    at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:526)
    at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:170)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:360)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307)
    ... 53 more
我什么都试过了。我花了几个小时来解决这个问题。我的假设是连接池配置不正确,或者事务范围(容器管理)EntityManager没有正确关闭连接

以下是该项目的一些代码片段:

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="projectPU" transaction-type="JTA">
    <jta-data-source>jdbc/project_customer_pool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" 
                 jndi-name="jdbc/project_customer_pool" 
                 object-type="user" 
                 pool-name="project_customer_pool">
    <description>Project Customer Pool</description>
  </jdbc-resource>
  <jdbc-connection-pool allow-non-component-callers="false" 
                        associate-with-thread="false" 
                        connection-creation-retry-attempts="0" 
                        connection-creation-retry-interval-in-seconds="10" 
                        connection-leak-reclaim="true" 
                        connection-leak-timeout-in-seconds="15"
                        statement-timeout-in-seconds="8"
                        statement-leak-timeout-in-seconds="4"
                        connection-validation-method="auto-commit" 
                        datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource" 
                        fail-all-connections="false" 
                        idle-timeout-in-seconds="300" 
                        is-connection-validation-required="false" 
                        is-isolation-level-guaranteed="true" 
                        lazy-connection-association="false" 
                        lazy-connection-enlistment="false" 
                        match-connections="false"
                        max-connection-usage-count="0" 
                        max-pool-size="32" 
                        max-wait-time-in-millis="60000" 
                        name="project_customer_pool" 
                        non-transactional-connections="false" 
                        pool-resize-quantity="2" 
                        res-type="javax.sql.ConnectionPoolDataSource" 
                        steady-pool-size="8" 
                        validate-atmost-once-period-in-seconds="0" 
                        wrap-jdbc-objects="false">
    <description>project db</description>
    <property name="serverName" value="localhost"/>
    <property name="portNumber" value="5432"/>
    <property name="databaseName" value="project"/>
    <property name="URL" value="jdbc:postgresql://localhost:5432/project"/>
    <property name="User" value="admin"/>
    <property name="Password" value="admin"/>
  </jdbc-connection-pool>
</resources>

jdbc/项目\客户\池
假的
glassfish resources.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="projectPU" transaction-type="JTA">
    <jta-data-source>jdbc/project_customer_pool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" 
                 jndi-name="jdbc/project_customer_pool" 
                 object-type="user" 
                 pool-name="project_customer_pool">
    <description>Project Customer Pool</description>
  </jdbc-resource>
  <jdbc-connection-pool allow-non-component-callers="false" 
                        associate-with-thread="false" 
                        connection-creation-retry-attempts="0" 
                        connection-creation-retry-interval-in-seconds="10" 
                        connection-leak-reclaim="true" 
                        connection-leak-timeout-in-seconds="15"
                        statement-timeout-in-seconds="8"
                        statement-leak-timeout-in-seconds="4"
                        connection-validation-method="auto-commit" 
                        datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource" 
                        fail-all-connections="false" 
                        idle-timeout-in-seconds="300" 
                        is-connection-validation-required="false" 
                        is-isolation-level-guaranteed="true" 
                        lazy-connection-association="false" 
                        lazy-connection-enlistment="false" 
                        match-connections="false"
                        max-connection-usage-count="0" 
                        max-pool-size="32" 
                        max-wait-time-in-millis="60000" 
                        name="project_customer_pool" 
                        non-transactional-connections="false" 
                        pool-resize-quantity="2" 
                        res-type="javax.sql.ConnectionPoolDataSource" 
                        steady-pool-size="8" 
                        validate-atmost-once-period-in-seconds="0" 
                        wrap-jdbc-objects="false">
    <description>project db</description>
    <property name="serverName" value="localhost"/>
    <property name="portNumber" value="5432"/>
    <property name="databaseName" value="project"/>
    <property name="URL" value="jdbc:postgresql://localhost:5432/project"/>
    <property name="User" value="admin"/>
    <property name="Password" value="admin"/>
  </jdbc-connection-pool>
</resources>

项目客户群
项目数据库
数据库访问对象(DAO):

@Stateless
public class DAO implements IDAO, Serializable {

    @PersistenceContext(unitName = "projectPU")
    private EntityManager em;

    // Example for a method
    @Override
    public Benutzer login(String email) {
        if (email.isEmpty()) {
            return null;
        }

        try {
            TypedQuery<User> qu = em.createQuery("FROM User u WHERE u.email = :email AND u.valid_to IS null", User.class);
            qu.setParameter("email", email);
            return qu.getSingleResult();
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
        return null;
    }
}
@无状态
公共类DAO实现IDAO,可序列化{
@PersistenceContext(unitName=“projectPU”)
私人实体管理者;
//方法示例
@凌驾
公共Benutzer登录(字符串电子邮件){
if(email.isEmpty()){
返回null;
}
试一试{
TypedQuery qu=em.createQuery(“从用户u,其中u.email=:email和u.valid\u to为null”,User.class);
qu.setParameter(“电子邮件”,电子邮件);
返回qu.getSingleResult();
}捕获(例外情况除外){
System.err.println(例如getMessage());
}
返回null;
}
}
我希望有人能帮我解决这个问题,或者知道如何解决它。我不知道该怎么办了


谢谢大家!

下载Postgres JDBC驱动程序并将其置于
C:\glassfish安装路径\domains\domain name\lib
下,然后重新启动glassfish@Nicholas:OP有一个不同的错误,你发布的链接怎么会有用?@perissf-它显示了配置示例。