在战争中使用jar时放置persistence.xml的位置?

时间:2016-07-01 02:22:17

标签: java jpa

我有以下项目:

hbo-service
hbo-web

hbo-service是hbo-web(war)的jar依赖,它使用JPA处理每个与持久性相关的功能。我在hbo-service的src / main / resources / META-INF中包含了以下persistence.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="HBOService">    
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521/xe"/>
        <property name="javax.persistence.jdbc.user" value="hbo"/>
        <property name="javax.persistence.jdbc.password" value="hbo"/>
    </properties>
</persistence-unit>

在glassfish中部署hbo-web时,我不断收到以下消息:

[2016-06-30T21:08:14.353-0500] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1467338894353] [levelValue: 1000] [[
Exception while deploying the app [hbo-web-1.0-SNAPSHOT] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): 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 1527 with message Connection refused: connect.Error Code: 0]]

我注意到无论我如何更改网址,它总是尝试在1527连接到localhost(你会在persistence.xml中注意到我试图连接到1521),就像我做的任何更改一样在部署时不会注意到文件中。我做错了什么?

这是我的web.xml以防万一:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >    

</web-app>

1 个答案:

答案 0 :(得分:0)

我终于找到了问题,并没有与persistence.xml文件有任何关系。

[2016-06-30T21:08:14.353-0500] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=47 _ThreadName=admin-listener(2)] [timeMillis: 1467338894353] [levelValue: 1000] [[
Exception while deploying the app [hbo-web-1.0-SNAPSHOT] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): 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 1527 with message Connection refused: connect.Error Code: 0]]

该消息显示1527端口存在问题,这是glassfish用于其连接池的端口。原来这项服务已经关闭,所以我只需要去Glassfish管理控制台并打开连接池。

希望它有所帮助!