How to configure AspectJ with Load Time Weaving without Interface

前端 未结 2 878
囚心锁ツ
囚心锁ツ 2021-01-30 19:06

On my project, I currently use AspectJ (not just Spring AOP due to some limitation) with the weaving at the Compile Time. In order to speed up the development on Eclipse, I want

2条回答
  •  生来不讨喜
    2021-01-30 19:25

    First of all , if you are using maven, set your pom.xml:

        
            org.springframework
            spring-instrument
            3.1.2.RELEASE
        
        
            org.aspectj
            aspectjweaver
            1.7
        
    

    Then you have had to compile your code using the aspectj compiler. This compiler generate an aop.xml file in META-INF/aop.xml

    (I'm using eclipse sts) After that, I want to run a Junit test. So you have to set your VM args in the eclipse run configuration window: -javaagent:${ASPECTJ_WEAVER_1.7}\aspectjweaver-1.7.0.jar -javaagent:${SPRING_INSTRUMENT}\spring-instrument-3.1.2.RELEASE.jar

    where ${ASPECTJ_WEAVER_1.7} ${SPRING_INSTRUMENT} are an environtment var. Use the var button to create these vars (is located at bottom right of the window). These vars target to the folders where the aspectjweaver-1.7.0.jar and spring-instrument-3.1.2.RELEASE.jar are located. Follow the asistant to make this. It's not difficult. Take care that the previous javaagent lines haven't any invisible strange character or similar. It's sound strange but I had to rewrite several times the same line until eclipse said that this line is fine.

    Then, you can run your Junit test. The first you can see is aspectj runtime loading. Later you will see spring loading... and after that your test will run is haven't got any spring problem or similar. This is a heavy process.

    I hope this information can help you

    Regards

提交回复
热议问题