简体   繁体   English

Spring从JBoss上下文加载PropertySourcesPlaceholderConfigurer

[英]Spring loading PropertySourcesPlaceholderConfigurer from JBoss context

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. 我有一个使用PropertySourcesPlaceholderConfigurer的spring 3.1应用程序加载设置,我想管理测试和生产环境,只需从本地文件属性中指定的服务器上下文覆盖设置加载设置。

Next example works fine with Tomcat, how can I do the same in JBoss AS 7.1? 下一个例子适用于Tomcat,我怎样才能在JBoss AS 7.1中做同样的事情?

In spring context I have: 在春天的背景下,我有:

<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>

In ApplicationTest.properties (that overrides Application.properties): 在ApplicationTest.properties中(覆盖Application.properties):

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

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

<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>

In this way all parameters specified in context.xml overrides parameters in ApplicationTest.properties. 这样,context.xml中指定的所有参数都会覆盖ApplicationTest.properties中的参数。

Is there a way to specify context parameter in JBoss? 有没有办法在JBoss中指定上下文参数? (ie in standalone.xml file) (即在standalone.xml文件中)

EDIT - SOLVED: 编辑 - 解决:

As suggested in the answers, if I put entries in WEB-INF/jboss-web.xml inside webapp that works: 正如答案中所建议的那样,如果我将web-INF / jboss-web.xml中的条目放在webapp中,那么它是有效的:

<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>

But my goal was to put the config file out of webapp. 但我的目标是将配置文件从webapp中删除。 I solved in this way, I load the config file from $SERVER/conf directory: 我用这种方式解决了,我从$ SERVER / conf目录加载配置文件:

<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>

If someone knows how to put Parameters in JBOSS config out of webapp (as TOMCAT) is well appreciated! 如果有人知道如何将JBOSS配置中的参数从webapp中取出(如TOMCAT),我们非常感谢!

Thanks All! 谢谢大家!

According to the JBoss7 documentation: 根据JBoss7文档:

In AS7 the file context.xml is ignored. 在AS7中,忽略文件context.xml。 Most of the old context.xml configuration has been moved to jboss-web.xml . 大多数旧的context.xml配置已移至jboss-web.xml

See here for more details. 有关详细信息,请参见此处

In older versions you could add these properties to context.xml as usual - JBoss use Tomcat as a servlet container. 在旧版本中,您可以像往常一样将这些属性添加到context.xml - JBoss使用Tomcat作为servlet容器。

Use a jboss-web.xml file. 使用jboss-web.xml文件。 This file specifically replaces context.xml from Tomcat. 此文件专门替换Tomcat中的context.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM