0

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 access the foo value in a Controller without instantiating a bean? Is there a way to do that?

2
  • Do you want to get the value in your controller without instantiating FooBean? Commented Jun 1, 2011 at 12:26
  • Why not use Danny's suggestion and inject ${foo} into your controller from a properties file? Commented Jun 1, 2011 at 12:38

2 Answers 2

4

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.