2017-09-05 42 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

相关问题