java静态代理,模拟Spring AOP,springaop,java静态代理,模拟S
分享于 点击 49904 次 点评:1
java静态代理,模拟Spring AOP,springaop,java静态代理,模拟S
java静态代理,模拟Spring AOP
package cn.outofmemory.aop;import java.util.Date;interface Hello { public void sayHello(String name);}class MyHello implements Hello{ @Override public void sayHello(String name) { System.out.println("Hello" +name); }}class HelloProxy implements Hello { private Hello hello; public HelloProxy(Hello hello){ this.hello = hello; } @Override public void sayHello(String name) { Logger.logging(Level.DEBUGE, "sayHello() method start!"); hello.sayHello(name); Logger.logging(Level.INFO, "sayHello() method end!"); }}enum Level { INFO,DEBUGE;}class Logger { public static void logging(Level level, String context) { if (level.equals(Level.INFO)) { System.out.println(new Date()+ " " + context); } if (level.equals(Level.DEBUGE)) { System.out.println(new Date() + " " + context); } }}public class AopTester { public static void main(String[] args) { Hello helloProxy = new HelloProxy(new MyHello()); helloProxy.sayHello(" Spring AOP!!"); }}
用户点评