【问题标题】:iajc weave particular aspects using aspect pathiajc 使用方面路径编织特定方面
【发布时间】:2016-12-21 11:25:21
【问题描述】:

我有一个库(比如 lib1),其中包含几个方面类(比如 aspect1.java 和 aspect2.java)。 我只想在我的服务代码中编织 aspect1.java。 这可能在编译时编织中使用 ant iajc 目标吗? 我知道通过在 aop.xml 中指定要编织的方面,这在加载时编织中是可能的。

iajc 中也有 aspectpath,但我不确定如何配置它以接受单个类文件而不是完整的 jar 文件。

<target name="weave-with-ajc">
    <ht-aj:standard-aj-weave>
        <inpath>
            <path path="${classes.dir}" />
        </inpath>
        <aspectpath>
            <path path="${standard.compile.classpath}" />
            <path path="${bp:[Library]pkg.classpath}" />
        </aspectpath>
    </ht-aj:standard-aj-weave>
</target>

我只想编织一个特定的方面,而不是库中的所有方面。请提出建议。

【问题讨论】:

    标签: ant aspectj compile-time-weaving


    【解决方案1】:

    已为编译时编织以及https://bugs.eclipse.org/bugs/show_bug.cgi?id=124460 添加了对 aop.xml 的支持

    【讨论】:

      【解决方案2】:

      尽管 mentioned enhancement 仍未实现,但它们提供了一种简单的方法来显式指定要在编译时编织的方面。在我的情况下,我使用 spring-aspects 编织 AnnotationBeanConfigurerAspect 以支持 @Configurable 注释,问题是在 spring-aspects.jar (@987654326 @support,JPA 异常翻译器等等)这不是我想要的(至少我想控制它)。基于this 的帖子,我正在使用以下解决方案:

      <iajc destDir="${module.bin.dir}" showWeaveInfo="true" >
         <inpath>
            <pathelement location="${module.bin.dir}" />
         </inpath>
         <classpath>
            <path refid="module.classpath" />
         </classpath>
         <aspectpath refid="module.classpath" />
         <inxml> <!-- this is the important part -->
            <fileset dir="${module.src.dir}">
               <include name="aop-ctw.xml"/>
            </fileset>
         </inxml>
      </iajc>
      

      aop-ctw.xml 位于源目录中:

      <?xml version="1.0"?>
      <aspectj>
         <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
      <!-- Now, I don't want these:
          <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
          <aspect name="org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect"/>
      -->
      </aspectj>
      

      如果没有找到aop-ctw.xmliajc 将遵循标准行为:编织所有可用的方面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-23
        • 1970-01-01
        • 2015-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-30
        • 1970-01-01
        相关资源
        最近更新 更多