我可以将方面编织到它所定义的相同maven模块中并进入第三方依赖项吗?

时间:2013-12-06 15:58:43

标签: maven aspectj aspectj-maven-plugin

我有一个多模块maven项目,其中包含以下相关模块的设置:

    • 公地应用内
      • 后端
      • 前端

模块前端内置于war中并部署在Tomcat上。模块后端是打包为jar的标准Java应用程序。我想要完成的只是使以下方面工作(在前端和后端):

@Aspect
public class VirtuosoSequenceSanitizerAspect {

    @Around("execution(* cz.cuni.mff.xrg.odcs.commons.app.facade.*Facade.save(..))")
    public Object sanitizeSequenceOnSave(ProceedingJoinPoint pjp) throws Throwable {
        // ... some code
    }

    @Before("execution(* org.eclipse.persistence.internal.descriptors.ObjectBuilder.assignSequenceNumber(java.lang.Object, org.eclipse.persistence.internal.sessions.AbstractSession))")
    public void rememberAssignSequence(JoinPoint jp) {
        // .. some code
    }
}

这个方面在commons-app-context.xml中设置为Spring bean,如下所示:

<!-- enable aspects -->
<aop:aspectj-autoproxy />

<!-- Aspect for fixing corrupted database sequences. -->
<bean id="sequenceAspect" class="cz.cuni.mff.xrg.odcs.commons.app.dao.VirtuosoSequenceSanitizerAspect" />

通过此设置,around建议正常工作,但不会触发之前的建议。根据我的结论,我得出结论,我需要使用aspectj-maven-plugin编织到第三方库。所以我将插件添加到pom.xml中,用于commons-app模块,如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <complianceLevel>1.7</complianceLevel>
        <showWeaveInfo>true</showWeaveInfo>
        <verbose>true</verbose>
        <!-- Weave EclipseLink dependency -->
        <weaveDependencies>
            <weaveDependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>eclipselink</artifactId>
            </weaveDependency>
        </weaveDependencies>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
    </dependencies>
</plugin>

在建议工作之前使用此插件,但周围的建议停止工作。我一直在努力设置正确,所以这两个建议都按预期工作,但无济于事。当构建commons-app模块日志时,两个建议都是编织的:

--- aspectj-maven-plugin:1.5:compile (default) @ commons-app ---
Join point 'method-execution(void cz.cuni.mff.xrg.odcs.commons.app.facade.ScheduleFacade.save(cz.cuni.mff.xrg.odcs.commons.app.scheduling.Schedule))' in Type 'cz.cuni.mff.xrg.odcs.commons.app.facade.ScheduleFacade' (ScheduleFacade.java:127) advised by around advice from 'cz.cuni.mff.xrg.odcs.commons.app.dao.VirtuosoSequenceSanitizerAspect' (VirtuosoSequenceSanitizerAspect.java:90)
Join point 'method-execution(void cz.cuni.mff.xrg.odcs.commons.app.facade.DPUFacade.save(cz.cuni.mff.xrg.odcs.commons.app.dpu.DPUTemplateRecord))' in Type 'cz.cuni.mff.xrg.odcs.commons.app.facade.DPUFacade' (DPUFacade.java:123) advised by around advice from 'cz.cuni.mff.xrg.odcs.commons.app.dao.VirtuosoSequenceSanitizerAspect' (VirtuosoSequenceSanitizerAspect.java:90)
Join point 'method-execution(void cz.cuni.mff.xrg.odcs.commons.app.facade.DPUFacade.save(cz.cuni.mff.xrg.odcs.commons.app.dpu.DPUInstanceRecord))' in Type 'cz.cuni.mff.xrg.odcs.commons.app.facade.DPUFacade' (DPUFacade.java:185) advised by around advice from 'cz.cuni.mff.xrg.odcs.commons.app.dao.VirtuosoSequenceSanitizerAspect' (VirtuosoSequenceSanitizerAspect.java:90)
Join point 'method-execution(void cz.cuni.mff.xrg.odcs.commons.app.facade.PipelineFacade.save(cz.cuni.mff.xrg.odcs.commons.app.pipeline.Pipeline))' in Type 'cz.cuni.mff.xrg.odcs.commons.app.facade.PipelineFacade' (PipelineFacade.java:134) advised by around advice from 'cz.cuni.mff.xrg.odcs.commons.app.dao.VirtuosoSequenceSanitizerAspect' (VirtuosoSequenceSanitizerAspect.java:90)
...

但是,当我将前端部署到Tomcat时,只会触发之前的建议。如何配置maven以始终编织这两个建议?

1 个答案:

答案 0 :(得分:0)

我的错误,我实际上发现,周围的建议被触发。我没有看到这个,因为代码没有达到我的预期。此外,我认为它没有被触发,因为没有命中调试器断点。从一个简短的谷歌搜索我找到了原因...

  

如果内联建议,调试器无法弄清楚要做什么   (我们仍然需要在这方面做一些与JSR 45相关的工作,并且   可能也是Eclipse调试器)。为了调试建议,你   还需要转到项目属性并关闭“内联”   围绕建议“AspectJ编译器选项。然后调试   希望按预期工作......