0
我已經THW以下項目:在戰爭中使用jar的時候把persistence.xml放在哪裏?
hbo-service
hbo-web
HBO服務是HBO的web(戰爭)的JAR依賴它處理使用JPA每持久性相關的功能。我列入的src /主/資源/ HBO服務的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-網頁時:
[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]]
我注意到無論我如何更改url,它總是會嘗試連接到本地主機1527(你會注意到在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>
通常xml文件位於源文件夾src/main/resources中。您的項目中是否有web.xml?可能是配置有問題。應該有在web.xml參考,這樣的:<的context-param> xxxxConfigLocation類路徑:persistence.xml中 PARAM值> 的context-param> –
Tiina
是。我的意思是src/main/resources,我會編輯。我沒有在web.xml中做任何配置。 –
然後我認爲你應該在web.xml中添加引用persistence.xml的配置,因爲你在src/main/resources中有xml,所以路徑只能使用「classpath:persistence.xml」。 –
Tiina