开发者

Spring PropertyPlaceholderConfigurer Default Properties Not Read

I am trying to embed activemq broker in a Tomcat. The code base will be deployed in different environments. I want to externalize some parameters, but want to provide default values for those parameters in case the deployed environment does not provide values for place holders.

This is what I have :

<property name="properties">
    <props>
        <prop key="embed.broker.networkConnectorURI">static:(failover:(tcp://server01:61616,tcp://server02:61616))
        </prop>
        <prop key="embed.broker.transportConnectorURI">vm://localhost:61616</prop>
    </props>
</property>

<bean id="broker" class="org.apache.activemq.broker.BrokerService"
    init-method="start" destroy-method="stop">
    <property name="networkConnectorURIs">
        <list>
            <ref >${emb开发者_JAVA技巧ed.broker.networkConnectorURI}</ref>
        </list>
    </property>
    <property name="transportConnectorURIs">
        <list>
            <value>${embed.broker.transportConnectorURI}</value>
        </list>
    </property>
    <property name="brokerName" value="embed-broker" />
</bean>

When I deploy this in an environment where the place holders are missing, Tomcat throws "Could not resolve placeholder 'embed.broker.networkConnectorURI' " error. In other words, the default values are not being picked up.

Any help would be appreciated.


To have some default values, go on this way:

<bean id="myServer" class="com.gordondickens.myapp.MyServerConfig">
<property name="serverName" value="${server.name?localhost}" />
<property name="serverPort" value="${server.port?25}" />
</bean>


Use a PropertyOverrideConfigurer instead of a PropertyPlaceholderConfigurer. That way your defaults specified in the context file will be used if no overriding property file entries are found.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜