2017-09-05 38 views

回答

0

最簡單的解決方案是創建數據源,然後將其設置爲默認數據源。那麼你甚至不需要在你的persistence.xml中設置數據源。

例如,以下CLI命令將創建數據源並設置默認數據源(java:comp/DefaultDataSource)。

embed-server 

# Configure the driver 
/subsystem=datasources/jdbc-driver=org.postgresql:add(driver-name=org.postgresql, driver-module-name=org.postgresql, driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource) 

# Configure the data source 
/subsystem=datasources/data-source=postgresql:add(driver-name=org.postgresql, jndi-name="java:/jdbc/PostgresDS", enabled=true, connection-url="jdbc:postgresql://localhost/testdb", user-name=user, password="password") 

# Change the default data source name java:comp/DefaultDataSource 
/subsystem=ee/service=default-bindings:write-attribute(name=datasource, value=java:/jdbc/PostgresDS) 

stop-embedded-server 

然後在persistence.xml只是刪除<jta-data-source>標籤。

+0

它可以用於單個應用程序,但它會產生類似的問題,就像我在項目中指定數據源一樣。我試圖讓應用程序和數據源名稱彼此不知道,並從應用程序部署中刪除表命名注意事項。這不幸的是可能會導致表命名衝突並強制執行另一種緊耦合。 – KG6ZVP

+0

這不是一個好的答案,但您可能正在尋找* -ds.xml部署描述符。 https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html/Administration_and_Configuration_Guide/chap-Datasource_Management.html#Deployment_of_-ds.xml_files。該文檔不是最大的,但你可以在這裏看到一個例子https://github.com/wildfly/quickstart/blob/11.x/kitchensink/src/main/webapp/WEB-INF/kitchensink-quickstart-ds。 XML#L22。 –

+0

ds的部署更糟糕,因爲它不僅要緊貼我想要避免的緊密耦合,還會引入其他部署複雜性。我認爲現在的問題是不管我想要做什麼都是可能的。 – KG6ZVP

相關問題