<bean id="helloSpeaker" class="com.hc.test.HelloSpeaker"/>
<aop:aspect id="logging" ref="logAdvice">
<aop:before pointcut="execution(* com.hc.test.IHello.*(..))" method="before"/>
</aop:aspect>
</aop:config>
public class HelloSpeaker implements IHello {
public void sayHello() throws Exception {
System.out.println("Hello baby !");
}
public void toHello() {
System.out.println("to hello to you");
}
}
public interface IHello {
public void sayHello() throws Exception;
public void toHello();
}
import org.aspectj.lang.JoinPoint;
public class LogAdvice {
public void before(JoinPoint jointPoint) {
System.out.println("........the before content of logging.......");
}
}
Hello baby !
........the before content of logging.......
to hello to you
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
public class LogAdvice {
public void before(JoinPoint jointPoint) {
System.out.println("........the before content of logging.......");
}
public void after(JoinPoint jointPoint) {
System.out.println("........the after content of logging.......");
}
public Object around(ProceedingJoinPoint jointPoint) {
System.out.println("........the begin around content of logging.......");
Object retVal = null;
try {
retVal = jointPoint.proceed();
} catch(Throwable throwable) {
}
System.out.println("........the end around content of logging.......");
return retVal;
}
public void throwing(JoinPoint jointPoint, Throwable throwable) {
System.out.println("........the trowing content of logging.......");
}
}
public class HelloSpeaker implements IHello {
public void test1() {
System.out.println("Hello test 1 !");
}
public void test2() {
System.out.println("Hello test 2 !");
}
public void test3() {
System.out.println("Hello test 3 !");
}
public void test4() throws Exception {
System.out.println("Hello test 4 !");
throw new Exception();
}
}
<bean id="helloSpeaker" class="com.hc.test.HelloSpeaker"/>
<aop:config>
<aop:aspect id="logging" ref="logBeforeAdvice">
<aop:before pointcut="execution(* com.hc.test.IHello.test1(..))" method="before"/>
<aop:after pointcut="execution(* com.hc.test.IHello.test2(..))" method="after"/>
<aop:around pointcut="execution(* com.hc.test.IHello.test3(..))" method="around"/>
<aop:after-throwing pointcut="execution(* com.hc.test.IHello.test4(..))" throwing="throwable" method="throwing"/>
</aop:aspect>
</aop:config>