【发布时间】:2014-11-19 14:39:51
【问题描述】:
我在 JBoss 中使用 liquibase 和 Java EE。我在项目中配置persistence.xml文件,指定我要使用的Data Source。
在 JBoss 配置中:
<datasources>
<datasource jta="true" jndi-name="java:jboss/datasources/WebStoriesDS" pool-name="java:jboss/datasources/WebStoriesDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/mydatabase</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
在项目的persistence.xml中:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/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">
<persistence-unit name="PersistenceUnit">
<jta-data-source>java:jboss/datasources/WebStoriesDS</jta-data-source>
</persistence-unit>
</persistence>
以及项目的web.xml:
<context-param>
<param-name>liquibase.datasource</param-name>
<param-value>java:jboss/datasources/WebStoriesDS</param-value>
</context-param>
好吧,正如您所见,我在 JBoss 中有 1 个数据源引用,在我的项目中有 2 个引用。我将如何在此处应用 DRY 原则并在 JBoss 配置中仅使用 1 个引用,在我的项目中仅使用 1 个引用?使用属性文件保存数据源名称?
我只需要配置它,当我需要更改名称时,我只在两个地方进行更改:在我的项目和 JBoss 配置中。
【问题讨论】:
标签: java jakarta-ee jboss web.xml liquibase