I've noticed that I can load a config parameter into a bean using something like this in application-context.xml
:
<beans:bean id="foo" class="com.foo.FooBean">
<beans:property name="foo" value="${foo}" />
</beans:bean>
What about if I want to acce开发者_StackOverflow社区ss the foo
value in a Controller without instantiating a bean? Is there a way to do that?
You can use the @Value
annotation with util:properties
<util:properties id="props" location="classpath:com/foo/bar/props.properties"/>
And in your controller class, assuming you have a property with key 'foo':
@Value("#{props.foo}")
public void setFoo(String foo) {
this.foo = foo;
}
You can use PropertyPlaceholderConfigurer
Please refer to this link to read more about it
http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/beans.html#beans-factory-placeholderconfigurer
精彩评论