乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      動態(tài)代理方法互調(diào),靜態(tài)成員類

       頭號碼甲 2020-05-31

      在日常使用,還有面試中,經(jīng)常會涉及到AOP的相關(guān)知識,AOP雖好,但是有一些小的細(xì)節(jié)注意不到,可能會被坑;

      1.動態(tài)代理類的方法互調(diào),被調(diào)用的方法會不會生成代理?

      2.靜態(tài)成員類,調(diào)用過程中會不會生成代理?

      對以上這些問題進(jìn)行測試:

      首頁,這是AOP切面代碼

      @Component
      @Aspect
      public class AopTest {
      
          @Pointcut("execution(public * com.wuzhiaite.javaweb.spring.serveice.AopServiceTest.*(..))")
          public void AopTest(){ }
      @Before(
      "AopTest()") public void doBefore(){ System.out.println("doBefore"); }
      @After(
      "AopTest()") public void doAfter(){ System.out.println("doAfter"); } }

       接下來:被代理類的代碼

      @Service
      public class AopServiceTest {
      
          public void testMethod(){
              new Inner().innerMethod();
              System.out.println("testMethod");
              this.testMethod2();
          }
          public void testMethod2(){
              System.out.println("testMethod22222222");
          }
      
          public static class Inner{
              public void innerMethod(){
                  System.out.println("innerMethod");
              }
          }
      
      }

      再接下來,測試以下:

      @RunWith(SpringJUnit4ClassRunner.class)
      @Slf4j
      @EnableAspectJAutoProxy
      public class SpringBootJavawebBaseApplicationTests {
      
          @Autowired
          private AopServiceTest service;
      
          @Test
          public void aopTest1(){
              service.testMethod();
              new AopServiceTest.Inner().innerMethod();//靜態(tài)內(nèi)部類并不會生成代理類
          }
      }

      測試出來的結(jié)果是:

       

       很顯然,靜態(tài)成員類和方法內(nèi)部調(diào)用的方法并沒有生成代理,至于原因,后面康康源碼再補(bǔ)充

       

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多