开发者

Spring JMX. Set the default value of @ManagedAtrribute through XML

开发者 https://www.devze.com 2023-02-13 00:37 出处:网络
I\'m using Spring 3.0.5 I have a @ManagedResource bean, for some of the @ManagedAttribute methods which I want to set a defaultV开发者_开发问答alue. Instead of setting it to a hardcoded value I want

I'm using Spring 3.0.5

I have a @ManagedResource bean, for some of the @ManagedAttribute methods which I want to set a defaultV开发者_开发问答alue. Instead of setting it to a hardcoded value I want to be able to read it from a property value at load time, since the default changes from environment to environment.

A snippet from my programs applicationContext.xml:

<context:mbean-export default-domain="sampleApp"/>
<bean id="managedBean" class="com.example.sampleBean">
    <constructor-arg value="Sample Bean"/>
    <constructor-arg value="${sample.property}"/>
</bean>

I believe I have to use the XML configuration to be able to do this, but haven't figured out how to do it yet.


You can add the following to your applicationContext.xml, it should expose the properties you are after:

<context:property-placeholder location="classpath:application.properties"/>

So if the application.properties file you are pointing to above contains a property called sample.property then Spring will use that to inject into your ${sample.property} placeholder.

For more details you can see the Spring reference here.

0

精彩评论

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