-
Feb 23rd, 2010, 03:20 AM
#1
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?
-
Feb 24th, 2010, 05:26 AM
#2
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
-
Mar 8th, 2010, 02:59 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules