弹簧加载时间编织未检测到带有@configurable注释的类 [英] Spring load time weaving not detecting class annotated with @configurable

查看:71
本文介绍了弹簧加载时间编织未检测到带有@configurable注释的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让AspectJ在主项目中对以@configurable注释的类执行加载时编织.没有设置任何字段,没有任何设置者被触及.

I'm having trouble getting AspectJ to perform load time weaving on a class annotated with @configurable in my main project. No fields get set and none of the setters are touched.

我认为配置本身没有问题,因为我已经提取了配置并在一个较小的沙箱项目中对其进行了测试.仅出于此目的,我将其包含在此问题中.

I don't think there's trouble with the configuration itself, because I've extracted the configuration and tested it on a smaller sandbox project. Just for the sake of it, I'll include it in this question though.

所以,我想知道:

  1. 在较大的项目中,是否有任何可能妨碍Spring/AspectJ检测此特定类的东西?
  2. 有什么方法可以检查spring是否知道问题所在的班级吗?

最后,无论我能提取什么代码(请谅解):

And lastly, whatever code I can extract (please excuse the obfuscation):

从配置XML:

<context:annotation-config />
<context:spring-configured />
<context:component-scan base-package="se.isydev" />
<context:component-scan base-package="se.istools" />
<aop:aspectj-autoproxy />
<context:load-time-weaver aspectj-weaving="on" />
<context:property-placeholder location="classpath:settings.properties" />
(...)
<bean class="com.company.ClassToBeWeaved"
    scope="prototype">      
    <property name="injectedBean" ref="injectedBean" />
</bean>

以及类本身:

@Configurable
public class ClassToBeWeaved {
    private InjectedBean injectedBean;

    @Required
    public void setInjectedBean() { ... }
}

好吧,事实证明,由于循环依赖关系,它无法正常工作.噢,亲爱的我,我喜欢研究遗留代码.尽管如此,我最初的问题仍然存在.

Well, turns out that it wasn't working due to a circular dependency. Oh deary me, I love working on legacy code. Still, my original questions remain.

推荐答案

您的问题的一些提示.

要使加载时织入与Spring一起工作,不仅需要正确配置 aop.xml ,而且还需要具有 spring-instrument.jar 和& amp; amp; ; spring-aspects.jar .

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.

这些jar文件包含它们自己的 aop.xml ,它们声明要处理的Spring方面:

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

  • @Transactional 支持
  • @Configurable 支持
  • JPA异常翻译支持
  • @Async 注释,用于计划支持
  • @Transactional support
  • @Configurable support
  • JPA Exception translation support
  • @Async annotation for scheduling support

后台会发生什么?

使用AspectJ加载时编织时, @Transactional @Configurable 实现不再基于 JDK代理 CGLIB代理,但真正的AspectJ 方面.

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.

要启用这些实际方面,您需要其他jar文件.该jar还可以在自己的aop.xml中包含这些方面的声明

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

有关如何将Spring与AspectJ集成的更多详细信息

More details on how to integrate Spring with AspectJ here

这篇关于弹簧加载时间编织未检测到带有@configurable注释的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆