dynamically create new object with Spring properties injected
<p>I want to create Foo objects on the fly, but I want one of Foo's fields to be filled in by a property value defined by Spring's xml file.</p>

<p>For instance, I have the following Foo class:</p>

<pre><code>public class Foo {
    @Value("${val1}")
    private String val1;

    private String val2

    public foo(String val2) {
        this.val2 = val2;
    }

    public String getVal1(){
        return val1;
    }

    public void setVal1(String val1) {
        this.val1 = val1;
    }
}
</code></pre>

<p>Now, I know that the @Value will come as null because my Foo object is not defined as a bean in my XML file.  But, I do not want to define it as a bean as I need to define val2 dynamically like so:</p>

<pre><code>Foo foo = new Foo("val2");
</code></pre>

<p>Is there a way to inject val1 into every instance of Foo that is created?  I know the <code>new</code> operator is outside the scope of Spring and therefore cannot inject the value, but I am mainly looking for any way to dynamically specify val2 in a new instance of Foo while also injecting val1 with Spring.</p>