Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧加载时间编织未检测到用@configurable注释的类_Java_Spring_Aspectj - Fatal编程技术网

Java 弹簧加载时间编织未检测到用@configurable注释的类

Java 弹簧加载时间编织未检测到用@configurable注释的类,java,spring,aspectj,Java,Spring,Aspectj,我很难让AspectJ在主项目中用@configurable注释的类上执行加载时编织。未设置任何字段,也未触及任何设置器 我认为配置本身没有问题,因为我已经提取了配置并在一个较小的沙箱项目上进行了测试。不过,为了方便起见,我会把它包括在这个问题中 所以,我想知道: 在这个更大的项目中,是否有任何东西可能会妨碍Spring/AspectJ检测这个特定类的错误 有没有办法检查spring是否知道有问题的类 最后,不管我能提取什么代码(请原谅混淆): 从配置XML: <context:annot

我很难让AspectJ在主项目中用@configurable注释的类上执行加载时编织。未设置任何字段,也未触及任何设置器

我认为配置本身没有问题,因为我已经提取了配置并在一个较小的沙箱项目上进行了测试。不过,为了方便起见,我会把它包括在这个问题中

所以,我想知道:

  • 在这个更大的项目中,是否有任何东西可能会妨碍Spring/AspectJ检测这个特定类的错误
  • 有没有办法检查spring是否知道有问题的类
  • 最后,不管我能提取什么代码(请原谅混淆):

    从配置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>
    
    编辑:


    事实证明,由于循环依赖,它无法工作。哦,天哪,我喜欢处理遗留代码。尽管如此,我最初的问题仍然存在。

    你可能忘记了使用“”。将
    -javaagent:path/to/aspectjweaver.jar
    -javaagent:path/to/spring agent.jar
    添加到您的命令行


    我还建议您
    @Autowire
    您的依赖项,而不是显式地注入它。

    我认为LTW需要在类路径上使用META-INF/aop.xml。它应该是这样的:

    <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>
    


    您是否有超过1个spring XML文件?我相信我有问题
    不在我的XML文件的“最父级”中。

    有关您的问题的一些提示

    要使加载时编织与Spring一起工作,不仅需要正确配置aop.xml,还需要使用Spring instrument.jar&Spring aspects.jar

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

    • @事务支持
    • @可配置支持
    • JPA异常翻译支持
    • @用于调度支持的异步注释
    背景中发生了什么?

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

    要启用这些真正的方面,您需要额外的jar文件。jar还包含这些方面在其自己的aop.xml中的声明


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

    您运行此应用程序的环境是什么?LTW只在某些应用程序服务器上工作。我在eclipse中运行了我的沙盒,正确的应用程序正在JBoss上运行。您正在运行哪个版本的JBoss,它的java启动命令行是什么?如果JBoss是5.x或更高版本,您不需要特定的代理(这与您的沙箱不同,您必须在沙箱中指定代理)-javaagent:(…)/spring-agent-2.5.6.jar“在我的命令行中。不,不需要它。正如我所说,它在我的沙盒中工作得很好。请参阅我的编辑。错误是由于代码中的循环依赖关系(不是我的)。
    <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>