Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Build-time weaving with @Configurable

  1. #1
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default Build-time weaving with @Configurable

    I have been able to use ajc (1.5.2) to effectively weave aspects declared with the @Aspect annotation. But I don't seem to be getting it to weave beans with the @Configurable annotation.

    I have tried to follow the instructions in the docs, but I am sure that I am missing something.

    I compiled with spring-aspects.jar in my classpath. I added:

    <aop:spring-configured/>

    to my application context. To be safe, I added:

    depends-on="org.springframework.beans.factory.aspectj.Anno tationBeanConfigurerAspect"

    to the first bean that executes on startup. And I added:

    @Configurable( autowire = Autowire.BY_NAME )

    to the domain object that I wanted to wire.

    However, on startup I get a null pointer exception because the dependency was never wired. Do I need to do something else to tell ajc how to weave this class?
    Corby

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    I believe that Spring2 still uses CGLIB by default so make sure your class/methods aren't final.

    Not definitive, just a quess.....this all might be a big fat lie
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  3. #3
    Join Date
    Nov 2005
    Posts
    10

    Default

    Quote Originally Posted by cepage
    However, on startup I get a null pointer exception because the dependency was never wired. Do I need to do something else to tell ajc how to weave this class?
    Have you tried getting ajc to print debug information during weaving? That made stuff a whole lot clearer for me when I tried load-time weaving.

  4. #4

    Default I have had it working with the lazy-init bean definition.

    It's a great little tool when it works. I am not sure it worked in all classes, but it definitely worked in some of them.

  5. #5
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default

    You are right, Thomas. My problem is not specific to build-time weaving. The @Configurable stuff is just not working consistently.

    I switched over to using the plain @Configurable() annotation, and explicitly declaring my beans as wired prototypes, and I get the same failures.

    Are there any test cases in the Nightly Build sources that demonstrates @Configurable working? I could use this as a baseline to file a bug report with a working counterexample.
    Corby

  6. #6
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    143

    Default

    I am also having problems with @Configurable.

    For example, take a standard bean class called Order
    Code:
    @Configurable
    public class Order implements Serializable
    {
    private Integer _deliveryMinuteWindowInterval;
    
    public Integer getDeliveryMinuteWindowInterval()
        {
            return _deliveryMinuteWindowInterval;
        }
    public void setDeliveryMinuteWindowInterval( Integer deliveryMinuteWindowInterval )
        {
            _deliveryMinuteWindowInterval = deliveryMinuteWindowInterval;
        }
    }
    My XML is defined as:
    Code:
    <aop:spring-configured/>
    
        <bean id="deliveryWindowMinuteInterval" class="java.lang.Integer">
            <constructor-arg>
                <value>15</value>
            </constructor-arg>
        </bean>
    
    <bean class="com.vodori.dolce.component.commerce.model.Order" lazy-init="true">
           <property name="deliveryMinuteWindowInterval" ref="deliveryWindowMinuteInterval" />
         </bean>
    However, everytime an order object is created anywhere in the system the deliveryMinuteWindowInterval is null....

    Any ideas? This is using RC3 snapshot from 7-26-2006

    Thanks!
    Grant Gochnauer
    Vodori Inc.
    Personal Blog

  7. #7
    Join Date
    Nov 2005
    Posts
    10

    Default

    Quote Originally Posted by GrantGochnauer
    Any ideas? This is using RC3 snapshot from 7-26-2006
    If this is all you have done, you have not made Spring aware of the Configurable annotation. <aop:spring-configured/> is _not_ enough. You either need to use load-time aspectj weaving, or you need to use the aspectj compiler to get compile-time weaving of the aspect related to the @Configurable annotation.

    This is described in several articles on the 'net. I suggest you have a look around for those.

  8. #8
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Hi cepage -

    Have u followed the instructions in section 7.7.4 ?

    - creation of aop.xml
    - add -javaagent:<path-to-ajlibs>/aspectjweaver.jar as VM arguments

    Regards.
    - Debasish

  9. #9
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default

    Quote Originally Posted by debasishg
    Hi cepage -

    Have u followed the instructions in section 7.7.4 ?

    - creation of aop.xml
    - add -javaagent:<path-to-ajlibs>/aspectjweaver.jar as VM arguments
    Section 6.7.4 specifies that those steps are necessary for load-time weaving, but I am performing build-time weaving. My understanding is that these steps are not necessary for build-time weaving. Thanks for your help, though.
    Corby

  10. #10
    Join Date
    Aug 2004
    Location
    Los Angeles, USA
    Posts
    62

    Default

    So are there any solution here to make this work with build-time weaving? I have AJDT installed and still I get the nullpointer with @Configurable. My domain object is created with the new operator in a AbstractDependencyInjectionSpringContextTests which loads the applicationcontext.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •