1

我有一个库(比如 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>

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

4

2 回答 2

0

尽管上述 增强功能仍未实现,但它们提供了一种简单的方法来显式指定要在编译时编织的方面。就我而言,我正在使用 spring-aspects 来编织AnnotationBeanConfigurerAspect以支持@Configurable注释,问题是在 spring-aspects.jar (支持、JPA 异常转换器等)中找到的所有@Transactional方面都进行了编织,这不是我想要的(至少我想控制这个)。基于这篇文章,我正在使用以下解决方案:

<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.xml未找到,iajc则采用标准行为:编织所有可用的方面。

于 2017-08-22T15:43:06.240 回答
0

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

于 2016-08-16T03:49:54.820 回答