# Configuring AOP with ZK to intercept methods.

javaenthu
141 2

Hi,
Before certain methods (or as of now all the methods) I have written an Aspect. All my other application is functioning correctly.
But none of the methods is getting called in the aspect class. I have modified my application-context.xml to support AOP.

The same cutpoint I tried in same folder structure in my local application but with ZK i am having issues. Am i missing something?

My Apect class is like this :

package com.mypckg.services.impl;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MyIntercpeter {

@Pointcut("execution(* com.mypckg.services.impl.MyService.getStudents(..))")
public void performance() {
}

@Before("performance()")
public void doSomethingBeforeExecution() {
System.out.println("Before execution method called...");

}

@AfterReturning("performance()")
public void doSomethingAfterExecution() {
System.out.println("After execution method called...");

}
}

The modifications I made in the application-context.xml are

<beans  .........

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="
..........
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

.....

<aop:aspectj-autoproxy />
<context:annotation-config />

delete retag edit

## 5 Replies

TonyQ
642
https://www.masterbranch....

Which class you are going to do AOP ?

Is that a composer or ?

javaenthu
141 2

I want to intercept all the methods of the application including Composer.
Thanks for showing interest and replying :)

And do you think what configurations I have added are correct?

TonyQ
642
https://www.masterbranch....

The keypoint is , as what I know, the AOP only work for those classes which is created by Spring .

If you are using apply="mypackage.MyComposrt" definition in your zul page,
it's created by ZK, so it might not work with your configurationm .

Usually if I have to work with Spring and Composers,
I will setup spring variable resolver and make sure there's a definition apply="\${myComposerBean}" in the zul page.

I didn't see your usage , so I might be wrong , just a quick guess. ;)

javaenthu
141 2

Thanks Tony.
I have 3 layers. (zk, composer, and DAO)
At the start of the each method and and at the return of the each method I want to do some logging.
And from zk i am calling directly composer methods, and in the composers DAO's are autowired.
Hope it helps to understand my scenario.

I didn't understand about variable resolver thing.

TonyQ
642
https://www.masterbranch....

Would you mind to provide some code snippets for your zul and composer code ?

That would make things more clear. ;)

[hide preview]