Spring loading PropertySourcesPlaceholderConfigurer from JBoss context

杀马特。学长 韩版系。学妹 提交于 2019-12-10 20:14:21

问题


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.

Next example works fine with Tomcat, how can I do the same in 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):

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

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

EDIT - SOLVED:

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>

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>

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

Thanks All!


回答1:


According to the JBoss7 documentation:

In AS7 the file context.xml is ignored. Most of the old context.xml configuration has been moved to 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.




回答2:


Use a jboss-web.xml file. This file specifically replaces context.xml from Tomcat.



来源:https://stackoverflow.com/questions/15502383/spring-loading-propertysourcesplaceholderconfigurer-from-jboss-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!