1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      SpringFramework中ProxyFactory的用法

      這篇文章主要講解了“SpringFramework中ProxyFactory的用法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“SpringFramework中ProxyFactory的用法”吧!

      成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比鼎城網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式鼎城網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋鼎城地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。

          Spring版本是5.0.4.release.

          ProxyFactory在Springaop中占有舉足輕重的地位,用來間接創(chuàng)建代理,如下List-1所示,我們給ServiceImpl創(chuàng)建代理。

          List-1

      public interface IService {
      
      	String hello();
      }
      
      public class ServiceImpl implements IService {
      	@Override
      	public String hello() {
      			System.out.println("service的hello方法");
      			return "Hello";
      	}
      }
      
      import org.springframework.aop.MethodBeforeAdvice;
      import java.lang.reflect.Method;
      
      public class BeforeAdvice implements MethodBeforeAdvice {
      
          @Override
          public void before(Method method, Object[] args, Object target) throws Throwable {
              System.out.println("beforeAdvice的before方法");
          }
      }
      
      import org.springframework.aop.AfterReturningAdvice;
      import java.lang.reflect.Method;
      
      public class AfterAdvice implements AfterReturningAdvice {
      
          @Override
          public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
              System.out.println("AfterAdvice的afterReturning方法");
          }
      }
      
      import org.junit.Test;
      import org.springframework.aop.framework.ProxyFactory;
      public class AopTest {
      
          @Test
          public void test(){
              ProxyFactory proxyFactory = new ProxyFactory();
              proxyFactory.setInterfaces(IService.class);
              proxyFactory.setTarget(new ServiceImpl());
              proxyFactory.addAdvice(new BeforeAdvice());
              proxyFactory.addAdvice(new AfterAdvice());
              IService proxy = (IService) proxyFactory.getProxy();
              String result = proxy.hello();
              System.out.println(result);
          }
      }

          運(yùn)行結(jié)果如下List-2

          List-2

      beforeAdvice的before方法
      service的hello方法
      AfterAdvice的afterReturning方法
      Hello

          proxyFactory.addAdvice(new BeforeAdvice())時(shí),會將Advice轉(zhuǎn)換為Advisor,最后再調(diào)用addAdvisor方法。

          當(dāng)我們調(diào)用ProxyFactory的getProxy時(shí),會先調(diào)用createAopProxy()->getAopProxyFactory().createAopProxy(this),AopProxyFactory是DefaultAopProxyFactory——在另一篇里面講到。createAopProxy方法里面把this傳入,ProxyFactory實(shí)現(xiàn)了AdvisedSupport,所以在createAopProxy時(shí)將ProxyFactory中設(shè)置的targetSource、advice等傳遞到了DefaultAopProxyFactory,之后傳遞到JdkDynamicAopProxy中。

          最后getProxy調(diào)用的是JdkDynamicAopProxy的getProxy方法,如下List-3所示,Proxy.newProxyInstance的方法中,最后的InvocationHandler是this——JdkDynamicAopProxy實(shí)現(xiàn)了InvocationHandler,所以當(dāng)我們調(diào)用目標(biāo)類的方法時(shí),會調(diào)用JdkDynamicAopProxy的invoke方法。

          List-3

      public Object getProxy(@Nullable ClassLoader classLoader) {
      	if (logger.isDebugEnabled()) {
      		logger.debug("Creating JDK dynamic proxy: target source is " + this.advised.getTargetSource());
      	}
      	Class[] proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised, true);
      	findDefinedEqualsAndHashCodeMethods(proxiedInterfaces);
      	return Proxy.newProxyInstance(classLoader, proxiedInterfaces, this);
      }

          這里就引出了一個(gè)問題,在JdkDynamicAopProxy的invoke方法中,攔截器鏈?zhǔn)窃趺礃?gòu)造出來了。

      感謝各位的閱讀,以上就是“SpringFramework中ProxyFactory的用法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對SpringFramework中ProxyFactory的用法這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!


      文章題目:SpringFramework中ProxyFactory的用法
      新聞來源:http://www.ef60e0e.cn/article/pjjsgc.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        周口市| 嘉峪关市| 东丽区| 行唐县| 于田县| 防城港市| 宝山区| 宁陵县| 新安县| 翁源县| 广丰县| 迁西县| 庄浪县| 时尚| 神池县| 荆门市| 永仁县| 泰顺县| 黄浦区| 临泽县| 韶关市| 平乡县| 措勤县| 蓝山县| 阜城县| 白朗县| 镇赉县| 北碚区| 仪征市| 罗田县| 图们市| 汶川县| 河曲县| 肃南| 布拖县| 化州市| 景谷| 福清市| 天台县| 阿尔山市| 安阳县|