Saturday, February 9, 2013

Spring context initialization fails after AspectJ upgrade

I was upgrading project's version of AspectJ to 1.7.1 to get Java 7 support. Nobrainer. But after the upgrade the application was not able to start up because of org.springframework.beans.factory.BeanCreationException: Error creating bean with name ... No matching factory method found: factory method 'aspectOf()' failure during Spring context initialization. Trying different versions showed the problem appeared in 1.6.11 version. Problem was in change aop.xml config file semantic.

Originally this kind of aop.xml was OK:

<aspectj>
    <weaver>
        <include within="cz.kara.foo..*"/>
    </weaver>
    <aspects>
        <aspect name="cz.kara.aspects.FooAspect"/>
    </aspects>
</aspectj>

But with a newer version the aop.xml has to be changed like this:

<aspectj>
    <weaver>
        <include within="cz.kara.foo..*"/>
        <include within="cz.kara.aspects..*"/>
    </weaver>
    <aspects>
        <aspect name="cz.kara.aspects.FooAspect"/>
    </aspects>
</aspectj>

While pre-1.6.11 the aspects did not need to be specified in weaver include section, they have to be specified there in later versions.