Friday, June 20, 2014

Simple Aspectj Example


import java.util.ArrayList;
import java.util.List;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class AspectJAnnotation {
    @Before("execution(* *.*())") // this will call on before every method call on spring framework Or you can change it depending on which spring package method you can to monitor
    public void beforeAnymethodcall(final JoinPoint thisJoinPoint) {

System.out.println("I am aspectj before call");
    }
   

    @After("execution(* *.*())") // this will call on after every method call on spring framework Or you can change it depending on which spring package method you can to monitor
    public void afterAnymethodcall(final JoinPoint thisJoinPoint) {
    System.out.println("I am aspectj after call");
    }
 




    }


public interface Listener {
abstract void EventFire();





}

public class ServiceImpl implements Listener{
void Method1(){
System.out.println("I am service");

}

@Override
public void EventFire() {

}

package TestJTest;

public class Testing {
void Method(){
System.out.println("This method is intercepted");
}
public static void main(String args[]){

ServiceImpl  test=new ServiceImpl();
test.Method1();


}
}


 

No comments:

Post a Comment