从JBoss上下文中春季加载PropertySourcesPlaceholderConfigurer [英] Spring loading PropertySourcesPlaceholderConfigurer from JBoss context

查看:118
本文介绍了从JBoss上下文中春季加载PropertySourcesPlaceholderConfigurer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用PropertySourcesPlaceholderConfigurer的Spring 3.1应用程序加载设置,并且我想仅通过从本地文件属性中指定的服务器上下文覆盖设置加载设置来管理测试和生产环境。

I have a spring 3.1 application loading settings using PropertySourcesPlaceholderConfigurer and I want to manage test and production environments simply loading settings from server context overriding settings specified in local file properties.

下一个示例在Tomcat上运行良好,如何在JBoss AS 7.1中执行相同的操作?

Next example works fine with Tomcat, how can I do the same in JBoss AS 7.1?

在春季,我有:

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="localOverride" value="false" />
    <property name="locations">
        <list>
            <value>classpath:Application.properties</value>
            <value>classpath:ApplicationTest.properties</value>
        </list>
    </property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

在ApplicationTest.properties中(覆盖Application.properties):

In ApplicationTest.properties (that overrides Application.properties):

jdbc.driverClassName=oracle.jdbc.OracleDriver
jdbc.url=jdbc:oracle:thin:@XXXX:1521:xxxx
jdbc.username=myUsername
jdbc.password=myPassword

在context.xml中(在Tomcat / conf中目录):

In context.xml (in Tomcat/conf directory):

<Context>
    ...
    <Parameter name="jdbc.driverClassName" value="oracle.jdbc.OracleDriver" override="false"/>
    <Parameter name="jdbc.url" value="jdbc:oracle:thin:@XXXX:1521:ProductionSID" override="false"/>
    <Parameter name="jdbc.username" value="myProductionUsername" override="false"/>
    <Parameter name="jdbc.password" value="myProductionPassword" override="false"/>
    ...
</Context>

通过这种方式,context.xml中指定的所有参数将覆盖ApplicationTest.properties中的参数。

In this way all parameters specified in context.xml overrides parameters in ApplicationTest.properties.

是否可以在JBoss中指定上下文参数? (即在standalone.xml文件中)

Is there a way to specify context parameter in JBoss? (i.e. in standalone.xml file)

编辑-已解决:

如果我在有效的webapp内的WEB-INF / jboss-web.xml中输入了条目,则提示:

As suggested in the answers, if I put entries in WEB-INF/jboss-web.xml inside webapp that works:

<jboss-web>
...
    <env-entry>
        <env-entry-name>jdbc.username</env-entry-name>
        <env-entry-value>myUsername</env-entry-value>
        <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
...
</jboss-web>

但是我的目标是将配置文件从webapp中删除。以这种方式解决的
,我从$ SERVER / conf目录中加载配置文件:

But my goal was to put the config file out of webapp. I solved in this way, I load the config file from $SERVER/conf directory:

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="false" />
    <property name="localOverride" value="false" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="locations">
        <list>
            <value>classpath:Application.properties</value>
            <value>classpath:ApplicationTEST.properties</value>
            <value>file:${catalina.home}\conf\ApplicationPRODUCTION.properties</value><!-- FOR TOMCAT -->
            <value>file:${jboss.server.base.dir}\configuration\ApplicationPRODUCTION.properties</value><!-- FOR JBOSS-->
        </list>
    </property>
</bean>

如果有人知道如何将JBOSS配置中的参数从Web应用程序中删除(作为TOMCAT),将不胜感激!

If someone knows how to put Parameters in JBOSS config out of webapp (as TOMCAT) is well appreciated!

谢谢大家!

推荐答案

根据JBoss7文档:

According to the JBoss7 documentation:


在AS7中,文件context.xml被忽略。大部分旧的context.xml
配置已移至 jboss-web.xml

有关更多详细信息,请参见此处

See here for more details.

在较旧的版本中,您可以像往常一样将这些属性添加到context.xml中-JBoss使用Tomcat作为servlet容器。

In older versions you could add these properties to context.xml as usual - JBoss use Tomcat as a servlet container.

这篇关于从JBoss上下文中春季加载PropertySourcesPlaceholderConfigurer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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