如何外部化JBOSS 7.1.1的persistence.xml属性? [英] How to externalize properties of persistence.xml for JBOSS 7.1.1?

查看:125
本文介绍了如何外部化JBOSS 7.1.1的persistence.xml属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的persistence.xml当前存在于应用程序war(位于META-INF文件夹中)。但是,要使应用程序跨多个DB运行,需要一次又一次地更改持久性。我想避免它。但是,我无法理解如何从例如将根据数据库更改的属性文件中配置persistence.xml中的属性(如方言),因此不能强迫我更新和重新部署战争。

My persistence.xml is currently present in the application war(in META-INF folder.). However, for the application to be run across multiple DBs the persistence needs to be changed again and again. I want to avoid it. But, I am not able to understand how will i configure the properties(like dialect) in the persistence.xml from, say, a property file which i would change based on my DB, hence not compelling me to update and redeploy my war.

如果我可以在提到其他数据库详细信息的standalone.xml中的数据源中配置方言,也可以解决我的问题。我无法确定该物业将是什么。
虽然我更喜欢第一个解决方案。

My problem can also be resolved if i can configure the dialect in the datasource in standalone.xml where i have mentioned other DB details. I am not being able to make out what the property would be. Though i would prefer a solution for the first one.

PS:我是Web App开发的新手。问题可能使您烦恼。 :D

PS: I am rookie in Web App development. Questions might annoy you. :D

推荐答案

我使用了一种适用于休眠状态的方法。

I use a method that works well for hibernate.

1)将休眠配置属性放在xml文件中(称为hibernate.cfg.xml,但这不是强制性的)

1) put the hibernate configuration properties in a xml file (call it hibernate.cfg.xml but it's not mandatory)

这是示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.search.default.directory_provider">ram</property>
    </session-factory>
</hibernate-configuration>

您只能在此处放置不以 hibernate.ejb开头的休眠属性

you can put there only hibernate properties that do not start with hibernate.ejb

2)创建一个jboss模块。非常简单假设您要调用模块com.myorganization.config,而不是在服务器安装的 modules 文件夹中创建目录结构:/ com / myorganization / config / main。在主文件夹中放入hibernate.cfg.xml文件和以下 module.xml 文件:

2) Create a jboss module. It's very simple. Suppose you want to call the module com.myorganization.config than create a directory structure in the modules folder of you server installation: /com/myorganization/config/main. In the main folder put the hibernate.cfg.xml file and the following module.xml file:

<?xml version="1.0" encoding="UTF-8"?>  
<module xmlns="urn:jboss:module:1.1" name="com.myorganization.config">  
    <resources>  
        <resource-root path="."/>  
    </resources>
</module>

3)在您的persistence.xml中添加以下属性:

3) In your persistence.xml adding the following property:

<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />

4)最后,在META-INF / MANIFEST.MF文件中添加以下行:

4) Finally, in the META-INF/MANIFEST.MF file add the following line:

Dependencies: com.myorganization.config

如果您喜欢maven,请使用maven-war-plugin来更改MANIFEST.MF:

If you like maven use the maven-war-plugin in order to change the MANIFEST.MF:

<configuration>
    <archive>
        <manifestEntries>
            <Dependencies>com.myorganization.config</Dependencies>
        </manifestEntries>
    </archive>
</configuration>

仅此而已。

这篇关于如何外部化JBOSS 7.1.1的persistence.xml属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆