首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Annotation兑现缓存,使用AOP的HotSwappableTargetSource

2012-09-03 
Annotation实现缓存,使用AOP的HotSwappableTargetSourceHotSwappableTargetSource是一个可以动态替换的对

Annotation实现缓存,使用AOP的HotSwappableTargetSource
HotSwappableTargetSource是一个可以动态替换的对象,这个类很有用,可以在运行期间动态替换目标对象。
如下配置:


新建一个ehcache的动态代理替换类
/** * 在当前Factory的都会cache. */ApplicationContext cxt  = new ClassPathXmlApplicationContext(new String[]{"annotation/ano.xml","annotation/bean.xml"});//TestI testI = (TestI) cxt.getBean("testI");TestI testI = (TestI)new EhCacheDynaProxy<Intabc>(cxt,"&dynaProxy","testI").getObject(); int a = 10;int b = 11;System.out.println(testI.add(a, b));System.out.println(testI.add(a, b));System.out.println(testI.xx(a));System.out.println(testI.xx(a)); Intabc intabc = new EhCacheDynaProxy<Intabc>(cxt,"&dynaProxy","intabc").getObject(); System.out.println(intabc.test(a, b));System.out.println(intabc.test(a, b));

可以看到EhCacheDynaProxy可以代理任何接口类,并动态的生成Ehcache代理对象,实现缓存.

热点排行