Created
January 13, 2009 00:13
-
-
Save bdeterling/46252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.aopalliance.intercept.MethodInterceptor; | |
import org.aopalliance.intercept.MethodInvocation; | |
import org.springframework.aop.framework.ProxyFactory; | |
public class AopTester { | |
public interface MyInterface { | |
public void doStuff(); | |
} | |
public static class ThingToWrap implements MyInterface { | |
public void doStuff() { | |
System.out.println("Doing stuff"); | |
} | |
} | |
public static class MyInterceptor implements MethodInterceptor { | |
public Object invoke(MethodInvocation method) throws Throwable { | |
System.out.println("Before"); | |
try { | |
return method.proceed(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} finally { | |
System.out.println("After"); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
ProxyFactory proxyFactory = new ProxyFactory(new ThingToWrap()); | |
proxyFactory.addAdvice(new MyInterceptor()); | |
MyInterface proxy = (MyInterface) proxyFactory.getProxy(); | |
proxy.doStuff(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment