Spring load time weaving not detecting class annotated with @configurable

旧城冷巷雨未停 提交于 2019-12-05 10:47:37

You possibly have forgotten to "weave". Add -javaagent:path/to/aspectjweaver.jar or -javaagent:path/to/spring-agent.jar to your comman line.

I also suggest that you @Autowire your dependency rather than explicitly inject it.

I believe the LTW requires a META-INF/aop.xml on your classpath. It should look like:

<aspectj>
    <!--
        Uncomment this is you need AOP logging <weaver options="-verbose
        -showWeaveInfo
        -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
    -->
    <weaver>
        <include within="com.xxx.MyClass" />
    </weaver>
    <aspects>
        <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
        <include within="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
    </aspects>
</aspectj>

Do you have more then 1 spring XML file? I believe I had a problem <aop:aspectj-autoproxy /> was not in the 'most parent' of my XML files.

Some hints for your question.

To make load time weaving work with Spring, not only you need to configure properly the aop.xml but you need ALSO to have the spring-instrument.jar & spring-aspects.jar.

These jar files contain their own aop.xml that declare Spring aspects to handle:

  • @Transactional support
  • @Configurable support
  • JPA Exception translation support
  • @Async annotation for scheduling support

What happen in the background ?

When using AspectJ load-time weaving, the @Transactional and @Configurable implementations are no longer based on JDK proxies or CGLIB proxies but real AspectJ aspects.

To enable these real aspects, you need the additional jar files. The jar also contain declaration of these aspects in their own aop.xml

More details on how to integrate Spring with AspectJ here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!