spring开发_AOP_代理模式

spring开发_AOP_代理模式,第1张

概述spring aop proxy 代理模式

href="http://www.cnblogs.com/hongten/gallery/image/112445.HTML">http://www.cnblogs.com/hongten/gallery/image/112445.HTML

> 代理对象 -------------->> 目标对象

com.b510.service; PersonService { save(String name); String getPersonname(Integer personID); update(String name,Integer personID); }

com.b510.service.impl; java.lang.reflect.InvocationHandler; java.lang.reflect.Method; java.lang.reflect.Proxy; JDKProxyFactory InvocationHandler { Object targetobject; Object createProxyInstance(Object targetobject) { .targetobject = targetobject; Proxy.newProxyInstance(.targetobject.getClass() .getClassLoader(), .targetobject.getClass().getInterfaces(),); } @OverrIDe Object invoke(Object arg0,Method method,Object[] arg) Throwable { PersonServiceBean bean = (PersonServiceBean) .targetobject; Object result = ; (bean.getUser() != ) { result = method.invoke(targetobject,arg); } result; } }

com.b510.service.impl; com.b510.service.PersonService; PersonServiceBean PersonService { String user = ; PersonServiceBean() { } PersonServiceBean(String user) { .user = user; } String getUser() { .user; } @OverrIDe String getPersonname(Integer personID) { System.out.println("this is the getPersonname() function"); "hongten"; } @OverrIDe save(String name) { System.out.println("this is the save() function"); } @OverrIDe update(String name,Integer personID) { System.out.println("this is the update() function"); } }

com.b510.test; com.b510.service.PersonService; com.b510.service.impl.JDKProxyFactory; com.b510.service.impl.PersonServiceBean; AOPTest { main(String[] args) { JDKProxyFactory factory = JDKProxyFactory(); PersonService service = (PersonService) factory .createProxyInstance( PersonServiceBean("hello")); service.save("hongten"); service.getPersonname(1); service.update("hello",2); System.out.println("*************************"); PersonService service1 = (PersonService) factory .createProxyInstance( PersonServiceBean()); service1.save("hongten"); service1.getPersonname(1); service1.update("hello",2); System.out.println("end"); } }

is the save() function is the getPersonname() function is the update() function ************************* end

 

总结

以上是内存溢出为你收集整理的spring开发_AOP_代理模式全部内容,希望文章能够帮你解决spring开发_AOP_代理模式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1270039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存