从JBoss 6 Web应用程序中的文件加载属性

从JBoss 6 Web应用程序中的文件加载属性,jboss,properties,jakarta-ee,Jboss,Properties,Jakarta Ee,我是否可以将属性文件转储到JBoss 6目录中的某个地方,然后从类路径中拾取它 甚至更好的是,有人知道像$JBOSS\u HOME/server/default/deploy/JBOSS logging.xml这样的配置文件背后的机制吗?对此文件的更改似乎会触发一个事件,以便运行的实例可以处理修改(而不必反弹AS) 可以在/conf/jboss service.xml中配置SystemPropertiesService 这允许您就地配置系统属性,或从属性文件加载它们: <server>

我是否可以将属性文件转储到JBoss 6目录中的某个地方,然后从类路径中拾取它


甚至更好的是,有人知道像
$JBOSS\u HOME/server/default/deploy/JBOSS logging.xml这样的配置文件背后的机制吗?对此文件的更改似乎会触发一个事件,以便运行的实例可以处理修改(而不必反弹AS)

可以在
/conf/jboss service.xml
中配置
SystemPropertiesService

这允许您就地配置系统属性,或从属性文件加载它们:

<server>
    <mbean code="org.jboss.varia.property.SystemPropertiesService"
           name="jboss.util:type=Service,name=SystemProperties">

        <!-- Load properties from each of the given comma seperated URLs -->
        <attribute name="URLList">
            http://somehost/some-location.properties,
            ./conf/somelocal.properties
        </attribute>

        <!-- Set propertuies using the properties file style. -->
        <attribute name="Properties">
            property1=This is the value of my property
            property2=This is the value of my other property
        </attribute>

    </mbean>
</server>


一种可能性是在
/conf/jboss service.xml
中配置
SystemPropertiesService

这允许您就地配置系统属性,或从属性文件加载它们:

<server>
    <mbean code="org.jboss.varia.property.SystemPropertiesService"
           name="jboss.util:type=Service,name=SystemProperties">

        <!-- Load properties from each of the given comma seperated URLs -->
        <attribute name="URLList">
            http://somehost/some-location.properties,
            ./conf/somelocal.properties
        </attribute>

        <!-- Set propertuies using the properties file style. -->
        <attribute name="Properties">
            property1=This is the value of my property
            property2=This is the value of my other property
        </attribute>

    </mbean>
</server>


在JBoss 6中使用:
/deploy/properties service.xml
在JBoss 6中使用:
/deploy/properties service.xml
在JBoss AS7 properties-service.xml上不再存在,以下是解决方案:


JBoss AS7 properties-service.xml上的已不存在,以下是解决方案:


他们在JBoss EAP 6(AS 7)中更容易做到这一点

  • 将属性文件作为启动参数传递
  • 这可以添加到主启动脚本中,也可以作为参数传递

    ./standalone.sh  --properties=/Users/john.galt/dev/config/ds/jboss.properties 
    
    如果读取这些属性,它们将作为第一条语句呈现在服务器日志中

    3:58:41,633 DEBUG [org.jboss.as.config] (MSC service thread 1-6) Configured system properties:
            DSsettings.password = password
            DSsettings.user-name = admin
            DSsettings.connection-url = jdbc:oracle:fat:@activedb:1521:DEV
            [Standalone] =
            awt.nativeDoubleBuffering = true
    
    注意:由于这些设置记录在服务器日志中,请确保生产中的属性文件中没有明文密码

  • 使用传入的系统属性 您可以使用以下语法使用这些系统属性。 数据源文件中的示例用法

    <xa-datasource jndi-name="java:jboss/ds" pool-name="cPool" jta="true" enabled="true" use-ccm="true">
        <xa-datasource-property name="URL">
    
            ${DSsettings.connection_url}
    
        </xa-datasource-property>
    
        <driver>oracle</driver>
        ...
        <security>
    
            <user-name>${DSsettings.user-name}</user-name>
    
            <password>${DSsettings.password}</password>
    
        </security>
        ...
    
    </xa-datasource>
    

    
    ${DSsettings.connection\u url}
    神谕
    ...
    ${DSsettings.user name}
    ${DSsettings.password}
    ...
    


  • 他们在JBossEAP6(AS 7)中使这一点更加容易

  • 将属性文件作为启动参数传递
  • 这可以添加到主启动脚本中,也可以作为参数传递

    ./standalone.sh  --properties=/Users/john.galt/dev/config/ds/jboss.properties 
    
    如果读取这些属性,它们将作为第一条语句呈现在服务器日志中

    3:58:41,633 DEBUG [org.jboss.as.config] (MSC service thread 1-6) Configured system properties:
            DSsettings.password = password
            DSsettings.user-name = admin
            DSsettings.connection-url = jdbc:oracle:fat:@activedb:1521:DEV
            [Standalone] =
            awt.nativeDoubleBuffering = true
    
    注意:由于这些设置记录在服务器日志中,请确保生产中的属性文件中没有明文密码

  • 使用传入的系统属性 您可以使用以下语法使用这些系统属性。 数据源文件中的示例用法

    <xa-datasource jndi-name="java:jboss/ds" pool-name="cPool" jta="true" enabled="true" use-ccm="true">
        <xa-datasource-property name="URL">
    
            ${DSsettings.connection_url}
    
        </xa-datasource-property>
    
        <driver>oracle</driver>
        ...
        <security>
    
            <user-name>${DSsettings.user-name}</user-name>
    
            <password>${DSsettings.password}</password>
    
        </security>
        ...
    
    </xa-datasource>
    

    
    ${DSsettings.connection\u url}
    神谕
    ...
    ${DSsettings.user name}
    ${DSsettings.password}
    ...