Take the 2-minute tour ×

I'm trying to configure a class with Annotation based configuration in Spring 3, which takes primitive values as its constructor arguments:

class MyBean {
  MyBean(String arg1, String arg2) {
    // ...

And an application context like this:

<beans [...]>
  <context:property-override location="/WEB-INF/example.properties" />

I'm trying to find some way to specify that the constructor arguments should be taken from the properties file. Apparently this does work with constructors that take regular beans (e.g. MyClass(Bean bean1, OtherBean bean2)), but just properties?

I have also tried annotating the constructor arguments with Spring 3's @Value annotation and an EL expression for the value, like @Value("#{prop.Prop1}") arg1, but that doesn't seem to work either.

share|improve this question

1 Answer 1

up vote 9 down vote accepted

The following code works fine with <context:property-placeholder .../>:

public class MyBean { 
    public MyBean(@Value("${prop1}") String arg1, @Value("${prop2}") String arg2) { 
        // ... 

But <context:property-override .../> is a very specific thing, it's not suitable here.

share|improve this answer
Will the property file have "myBean.prop1=foo" or just "prop1=foo"? That is, are the properties scoped by bean name? –  Martin Probst Feb 22 '10 at 11:58
Property file will have prop1=foo. If you need myBean.prop1=foo, write @Value("${myBean.prop1}"). It's the way how <context:property-placeholder .../> works. –  axtavt Feb 22 '10 at 15:04

Your Answer


