title: Spring - creating objects with new operator using @Configurable & @Value annotations
body: <p>Is it possible to use @Configurable on a class that's weaved using AspectJ and get Spring to load in values on fields/methods which are annotated with @Value?</p>
  
  <p>I know its possible with @Autowired and @Resource etc... Are there any others. </p>
  
  <p>e.g. </p>
  
  <pre><code>@Configurable
  public Class MyObj{
   @Value("$(my.prop)")
   private String aField;
  
   public String getAField(){
     return aField;
   }
  }
  </code></pre>
  
  <p>And then have something like</p>
  
  <pre><code>public aMethodSomewhereElse(){
     MyObj obj = new MyObj()
     assertNotNull(obj.getAField());
  }
  </code></pre>
  
  <p>Are there any alternatives to being able to create <code>MyObj</code> with the <code>new</code> operator and still get spring to handle the annotations?</p>
  
  <p><strong>--EDIT:--</strong></p>
  
  <p><strong>It IS possible to do this using <code>new</code> when using @Autowired</strong>, have a look at some Hibernate and JPA stuff with Spring and AOP... I've used this in the past to do some profiling of Java code. But I really want to use SPEL and @Value before I mock up a full example I was hoping to find the answer here. FYI - if you don't belive me the Spring Manual even says it is possible to do this, what I want to know is if its possible to use <strong>@Value</strong> annotations in the same scope... </p>
  
  <blockquote>
    <p>The Spring container instantiates and configures beans defined in your
    application context. It is also possible to ask a bean factory to
    configure a pre-existing object given the name of a bean definition
    containing the configuration to be applied. <strong>The spring-aspects.jar
    contains an annotation-driven aspect that exploits this capability to
    allow dependency injection of <em>any</em> object.</strong></p>
  </blockquote>
  
  <p>And...</p>
  
  <blockquote>
    <p>Using the annotation on its own does nothing of course. It is the
    AnnotationBeanConfigurerAspect in spring-aspects.jar that acts on the
    presence of the annotation. In essence the aspect says "after
    returning from the initialization of a new object of a type annotated
    with @Configurable, configure the newly created object using Spring in
    accordance with the properties of the annotation". In this context,
    initialization refers to newly instantiated objects (e.g., <strong><em>objects
    instantiated with the 'new' operator</em></strong>) as well as to Serializable
    objects that are undergoing deserialization (e.g., via readResolve()).</p>
  </blockquote>
  
  <p><a href="http://static.springsource.org/spring/docs/3.0.0.RC2/reference/html/ch07s08.html" rel="noreferrer">http://static.springsource.org/spring/docs/3.0.0.RC2/reference/html/ch07s08.html</a></p>
  
  <p>Cheers.</p>