在 Java EE 中,我提供了 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="ArticleManagement">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.pauljabines.portfolio.Article</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="************************" />
<property name="eclipselink.logging.level" value="ALL" />
</properties>
</persistence-unit>
</persistence>
问题:有了这些连接属性,为什么 glassfish 会抛出错误并说无法连接到端口 1527?
这是一些堆栈跟踪:
org.glassfish.deployment.common.DeploymentException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1,527 with message Connection refused: connect.
解决方案是在glassfish中为postgresql创建一个jdbc连接池。为此: