AOP 之 HelloWorld

2016-11-12  本文已影响54人  zlb
package com.zlb.service;
public interface IHelloWorldService {
    public void sayHello();
}
package com.zlb.service.imp;
import com.zlb.service.IHelloWorldService;
public class HelloWorldService implements IHelloWorldService{
    @Override
    public void sayHello() {
          System.out.println("============Hello World!");  
    }
}
package com.zlb.aop;
import org.aspectj.lang.ProceedingJoinPoint;
public class HelloWorldAspect {
     //前置通知  
    public void beforeAdvice() {  
        System.out.println("===========before advice");  
    }  
} 
<bean id="helloWorldService"   class="com.zlb.service.imp.HelloWorldService"/>  
<bean id="aspect" class="com.zlb.aop.HelloWorldAspect"/>  
<aop:config>  
    <aop:pointcut id="pointcut" expression="execution(* com.zlb.service.*.*(..))"/>  
    <aop:aspect ref="aspect">  
        <aop:before pointcut-ref="pointcut" method="beforeAdvice"/>  
    </aop:aspect>  
</aop:config>
===========before advice
============Hello World!admin
===========after finally advice
上一篇下一篇

猜你喜欢

热点阅读