Weave external aspect with new pointcut [duplicate]

偶尔善良 提交于 2019-12-12 02:53:47

问题


I'm pretty new to AOP in general, but I have the following problem.

I have 2 projects. One containing an aspect that does some performance testing and another project which has a dependency to the previous one.

What I'd like to achieve is weave the aspect from project 1, into another aspect of project 2. As such doing some performance testing on the aspect of project 2.

I found out it's not possible with Spring-AOP, but it should be possible with AspectJ's weaving. However, I did not figure out how.

Im pretty sure I need to make use of the aspectj-maven-plugin, using configuration as listed in the AspectJ documentation. But nothing seems to be picked up? Any pointers on how to write an extra pointcut for an external aspect?


回答1:


I didn't use aspectj-maven-plugin, instead i use load-time-weaving and it works fine.

are you gonna use aspectj language to define your aspects? if not, i suggest load-time-weaving




回答2:


It would have been a good idea to post your relevant maven pom.xml fragments, without that, I can only have a guess at your problem: did you specify your project 1 dependency as an aspect library in your aspectj-maven-plugin configuration in your pom.xml? Example taken from the aspectj-maven-plugin documentation and modified:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    <configuration>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>group.id.of.project.1</groupId>
                <artifactId>artifact.id.of.project.1</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

You'll also need the dependency on your classpath too, but I guess you have that already.



来源:https://stackoverflow.com/questions/36016143/weave-external-aspect-with-new-pointcut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!