Results 1 to 3 of 3

Thread: AspectJ is not working in Groovy

  1. #1
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    6

    Post AspectJ is not working in Groovy

    I have tried to do some sample using groovy and @aspectJ, created a groovy class like

    class sampleGroovy{
    def getDocument(){
    println "Inside sampleGroovy"
    }
    }

    and created a @aspectJ class with pointcut

    @aspect
    class CacheAspect {

    @Around("execution(* sampleGroovy.getDocument())")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
    println "Inside the AROUND"
    }

    @Before("execution(* sampleGroovy.getDocument())")
    public void doBeforeAccessCheck() {
    println "Inside Before"
    }

    @AfterReturning("execution(* sampleGroovy.getDocument())")
    public void doAfterAccessCheck() {
    println "Inside After"
    }
    }

    and applicationContext.xml beans are below

    <aop:aspectj-autoproxy />
    <bean id="cacheAspect" class="CacheAspect" />

    i have tried to execute the method but before, after and around method is not executed.

    i have tried to replace groovy file with java, then it is working fine..

    please let me know why it is not working?

  2. #2
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    6

    Default

    Able to make it up, but found some error.

    @Around("execution(* sampleGroovy.getDocument())")

    replace by

    @Around("execution(* sampleGroovy.*(..))")

    then i can able to get the console output but each method is called twice for the single request.

    please help me
    advance thanks

  3. #3
    Join Date
    Aug 2008
    Location
    Vancouver, BC
    Posts
    750

    Default

    The aspectj compiler cannot compile groovy source code. That is why you are having problems. However, you could try binary weaving of your groovy files. To do this, you must first compile your groovy files to class files. And then you must add the groovy class files to the inpath of the compilation of your aspectj files.

    Doing this is different depending on how you compile your code. If you are in Eclipse/STS, then:
    • select your AspectJ project -> Properties -> AspectJ Build Path -> In Path.
    • Then add the bin folder of the Groovy project to the in path.
    • Go to Java Build Path and *remove* the project reference to your groovy project
    • Now do a full build of both projects


    You should be all set to go, except for one thing: launching. You must launch your app within the context of the ApsectJ application (because the woven groovy files exist in the output folder of that project, not the groovy project).

    If you are not running within Eclipse/STS, let me know and I'll tell you how you should be compiling.
    Andrew Eisenberg, Ph.D.
    SpringSource, a division of VMware
    SpringSource Tools Team
    More about AJDT, Groovy-Eclipse, and Grails tooling

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •