ITeye博客

AOP

共 3 篇文章

Spring AOP Sample Code

转自 http://www.iteye.com/topic/40725 Before Advice 代码 1. package test3; 2. public class MessageWriter { 3. public void writeMessage() { 4. System.out.print("World"); 5. } 6. } 7. 8. package test3; 9. import java.lang.reflect.Method; 10. import org.springframework.aop.MethodBeforeAdvice; 11. import o…

2007-08-27 00:03 · AOP · Spring · AOP · Bean

cglib实现AOP

CGLib与java标准库提供的实现方案不同,cglib主要是基于实现类(如StudentInfoServiceImpl.java)扩展一个子类 来实现。与Dynamic Proxy中的Proxy和InvocationHandler相对应,net.sf.cglib.proxy.Enhancer和 MethodInterceptor在CGLib中负责完成代理对象创建和方法截获处理,产生的是目标类的子类而不是通过接口来实现方法拦截的, Enhancer主要是用于构造动态代理子类来实现拦截,MethodInterceptor(扩展了Callback接口)主要用于实现around advice(AO…

2007-08-22 17:17 · AOP · Java · Apache · .net · AOP · log4j

动态代理类(Proxy)

使用一个动态代理类(Proxy),通过拦截一个对象的行为并添加我们需要的功能来完成。Java中的java.lang.reflect.Proxy类 和java.lang.reflect.InvocationHandler接口为我们实现动态代理类提供了一个方案,但是该方案针对的对象要实现某些接 口;如果针对的目的是类的话,cglib为我们提供了另外一个实现方案。 一、接口的实现方案: java 代码 public interface StudentInfoService{ void findInfo(String studentName); } public class StudentInfoS…

2007-08-22 16:51 · AOP · Java · Apache · log4j