{"id":85463,"date":"2026-07-27T15:41:27","date_gmt":"2026-07-27T07:41:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/85463.html"},"modified":"2026-07-27T15:41:27","modified_gmt":"2026-07-27T07:41:27","slug":"15-%e9%9d%a2%e8%af%95%e5%ae%98%ef%bc%9aspring-aop-%e7%94%a8-jdk-%e4%bb%a3%e7%90%86%e8%bf%98%e6%98%af-cglib%ef%bc%9f%e4%bd%a0%e7%ad%94%e5%af%b9%e4%ba%86%e4%bd%86%e6%b2%a1%e8%af%b4%e4%b8%ba%e4%bb%80","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/85463.html","title":{"rendered":"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48"},"content":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u5256\u6790 Spring AOP \u7684\u4ee3\u7406\u673a\u5236&#xff0c;\u4ece JDK \u52a8\u6001\u4ee3\u7406\u4e0e CGLIB \u7684\u672c\u8d28\u5dee\u5f02\u3001Spring \u7684\u4ee3\u7406\u9009\u62e9\u903b\u8f91\u3001AOP \u901a\u77e5\u94fe\u6267\u884c\u987a\u5e8f&#xff0c;\u5230\u5e38\u89c1\u4ee3\u7406\u5931\u6548\u573a\u666f\u4e0e\u6392\u67e5\u65b9\u6cd5\u3002\u6587\u7ae0\u4e0d\u4ec5\u5bf9\u6bd4\u4e86\u4e24\u79cd\u4ee3\u7406\u65b9\u5f0f\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u6027\u80fd\u8003\u91cf&#xff0c;\u8fd8\u7ed3\u5408\u6e90\u7801\u89e3\u8bfb\u4e86 Spring \u7684\u4ee3\u7406\u4f18\u5148\u7ea7\u89c4\u5219&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u9762\u8bd5\u6807\u51c6\u56de\u7b54\u4e0e\u5b9e\u6218\u907f\u5751\u6307\u5357&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5f7b\u5e95\u7406\u89e3 AOP \u4ee3\u7406\u7684\u5e95\u5c42\u884c\u4e3a\u4e0e\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727074124-6a670ba4e040a.png\" \/><\/p>\n<p>\u9762\u8bd5\u95ee Spring AOP&#xff0c;\u5341\u4e2a\u5019\u9009\u4eba\u4e5d\u4e2a\u4e0a\u6765\u5c31\u662f&#034;JDK \u52a8\u6001\u4ee3\u7406\u548c CGLIB&#034;\u3002\u4f60\u8bf4\u51fa\u8fd9\u4e24\u4e2a\u540d\u8bcd\u6211\u53ea\u80fd\u7ed9\u4f60\u5bf9\u52fe&#xff0c;\u4e0d\u4f1a\u7ed9\u52a0\u5206\u3002<\/p>\n<p>\u4e09\u6863\u7b54\u6848\u7684\u5dee\u8ddd&#xff1a;\u7b2c\u4e00\u6863\u8bf4&#034;\u9ed8\u8ba4 JDK \u52a8\u6001\u4ee3\u7406&#xff0c;\u6ca1\u63a5\u53e3\u7528 CGLIB&#034;\u2014\u2014\u80cc\u7684&#xff0c;\u8ffd\u95ee&#034;\u600e\u4e48\u5f3a\u5236\u5207 CGLIB&#034;\u5c31\u5361\u58f3\u3002\u7b2c\u4e8c\u6863\u8bf4&#034;JDK \u57fa\u4e8e\u63a5\u53e3&#xff0c;CGLIB \u57fa\u4e8e\u7ee7\u627f&#xff0c;Spring Boot 2.0 \u540e\u9ed8\u8ba4 CGLIB&#034;\u2014\u2014\u6709\u4fe1\u606f\u91cf\u4e86&#xff0c;\u4f46\u8fd8\u662f\u6ca1\u56de\u7b54\u6838\u5fc3\u95ee\u9898\u3002\u7b2c\u4e09\u6863&#xff0c;\u662f\u4ece DefaultAopProxyFactory \u6e90\u7801\u4e00\u884c\u884c\u8bf4\u51fa\u4ee3\u7406\u4f18\u5148\u7ea7\u89c4\u5219&#xff0c;\u5e76\u80fd\u89e3\u91ca\u5e95\u5c42\u5b57\u8282\u7801\u884c\u4e3a\u5dee\u5f02\u7684\u4eba\u3002<\/p>\n<p>\u9762\u8bd5\u5b98\u5fc3\u91cc\u5176\u5b9e\u5728\u7b49\u4e09\u6837\u4e1c\u897f&#xff1a;\u4f60\u77e5\u4e0d\u77e5\u9053\u4ee3\u7406\u7684\u672c\u8d28\u662f&#034;\u8fd0\u884c\u65f6\u521b\u5efa\u5b57\u8282\u7801\u5b50\u7c7b&#034;\u3001\u4f60\u77e5\u4e0d\u77e5\u9053\u5b83\u4e3a\u4ec0\u4e48\u6709\u65f6&#034;\u4e0d\u751f\u6548&#034;\u3001\u4f60\u77e5\u4e0d\u77e5\u9053 Spring \u5728\u4ec0\u4e48\u573a\u666f\u4e0b\u4f1a\u9009\u54ea\u4e2a\u4ee3\u7406\u65b9\u5f0f\u5e76\u7ed9\u51fa\u7406\u7531\u3002 \u8fd9\u4e09\u6837\u7b54\u5168\u4e86&#xff0c;\u8fd9\u9053\u9898\u4f60\u5c31\u62ff\u6ee1\u5206\u4e86\u3002<\/p>\n<hr \/>\n<h3>\u4ee3\u7406\u6a21\u5f0f\u672c\u8d28&#xff1a;\u5077\u6881\u6362\u67f1<\/h3>\n<p>\u4f60 &#064;Autowired \u6ce8\u5165\u7684 UserService&#xff0c;\u65e9\u5c31\u4e0d\u662f\u4f60\u81ea\u5df1\u5199\u7684\u90a3\u4e2a UserServiceImpl \u4e86\u2014\u2014\u662f Spring \u5e2e\u4f60\u5305\u7684\u4e00\u5c42\u4ee3\u7406\u5bf9\u8c61\u3002\u4ee3\u7406\u5bf9\u8c61\u5728\u8c03\u771f\u6b63\u65b9\u6cd5\u4e4b\u524d\u63d2\u5165\u4e86\u5207\u9762\u903b\u8f91&#xff08;\u65e5\u5fd7\u3001\u6743\u9650\u3001\u4e8b\u52a1&#xff09;\u3002\u4f60\u4ece\u5934\u5230\u5c3e\u6ca1\u611f\u77e5\u5230\u4ee3\u7406\u7684\u5b58\u5728\u2014\u2014\u8fd9\u5c31\u662f AOP\u3002<\/p>\n<p>\u5177\u4f53\u662f\u600e\u4e48\u5305\u7684&#xff1f;Spring \u5bb9\u5668\u542f\u52a8\u65f6&#xff0c;AbstractAutoProxyCreator&#xff08;\u4e00\u4e2a BeanPostProcessor&#xff09;\u5728 Bean \u521d\u59cb\u5316\u7684 postProcessAfterInitialization \u9636\u6bb5&#xff0c;\u68c0\u67e5\u8fd9\u4e2a Bean \u662f\u5426\u9700\u8981\u4ee3\u7406\u2014\u2014\u904d\u5386\u6240\u6709 Advisor&#xff0c;\u7528 Pointcut \u5339\u914d Bean \u7684\u65b9\u6cd5&#xff0c;\u5982\u679c\u547d\u4e2d\u5c31\u521b\u5efa\u4ee3\u7406\u5bf9\u8c61\u66ff\u4ee3\u539f\u59cb Bean\u3002\u8fd9\u4e2a\u66ff\u6362\u8fc7\u7a0b\u662f\u900f\u660e\u7684&#xff0c;\u4f60\u62ff\u5230\u7684\u5f15\u7528\u5df2\u7ecf\u662f\u4ee3\u7406\u4e86\u3002<\/p>\n<p>\u95ee\u9898\u6765\u4e86&#xff1a;\u8fd9\u5c42\u4ee3\u7406\u5230\u5e95\u600e\u4e48&#034;\u5305&#034;\u51fa\u6765\u7684&#xff1f;<\/p>\n<hr \/>\n<h3>JDK \u52a8\u6001\u4ee3\u7406&#xff1a;\u5fc5\u987b\u6709\u63a5\u53e3\u2014\u2014\u4ee5\u53ca\u5b83\u5230\u5e95\u751f\u6210\u4e86\u4ec0\u4e48<\/h3>\n<p>UserService proxy &#061; (UserService) Proxy.newProxyInstance(<br \/>\n    target.getClass().getClassLoader(),<br \/>\n    target.getClass().getInterfaces(),<br \/>\n    (proxy, method, args) -&gt; {<br \/>\n        System.out.println(&#034;\u524d\u7f6e\u589e\u5f3a&#034;);<br \/>\n        return method.invoke(target, args);<br \/>\n    }<br \/>\n);<\/p>\n<p>Proxy.newProxyInstance() \u5728\u8fd0\u884c\u65f6\u52a8\u6001\u751f\u6210\u4e00\u4e2a\u5b9e\u73b0\u4e86\u6307\u5b9a\u63a5\u53e3\u7684\u5b57\u8282\u7801\u7c7b\u3002\u6838\u5fc3\u9650\u5236&#xff1a;\u53ea\u80fd\u4ee3\u7406\u63a5\u53e3\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5&#xff0c;\u5982\u679c\u76ee\u6807\u7c7b\u6709 public \u65b9\u6cd5\u4f46\u4e0d\u5728\u63a5\u53e3\u91cc&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u65e0\u6cd5\u8c03\u7528\u3002\u4e14\u4ee3\u7406\u5bf9\u8c61\u7684\u7c7b\u578b\u662f\u5b9e\u73b0\u7c7b\u63a5\u53e3\u7684\u533f\u540d\u7c7b&#xff0c;\u4e0d\u80fd\u5f3a\u8f6c\u4e3a\u5177\u4f53\u5b9e\u73b0\u7c7b\u2014\u2014UserService proxy \u53ef\u4ee5&#xff0c;UserServiceImpl proxy \u70b8\u3002<\/p>\n<p>\u4f46\u9762\u8bd5\u5b98\u5982\u679c\u518d\u8ffd\u95ee\u4e00\u53e5&#034;\u751f\u6210\u7684\u4ee3\u7406\u7c7b\u957f\u4ec0\u4e48\u6837&#034;\u2014\u2014\u5927\u90e8\u5206\u4eba\u7b54\u4e0d\u4e0a\u6765\u3002JDK \u52a8\u6001\u4ee3\u7406\u751f\u6210\u7684\u7c7b\u540d\u901a\u5e38\u662f $Proxy0\u3001$Proxy1 \u8fd9\u79cd\u683c\u5f0f&#xff0c;\u5b83\u7684\u7236\u7c7b\u662f java.lang.reflect.Proxy&#xff08;\u4e0d\u662f\u4f60\u7684\u76ee\u6807\u7c7b&#xff01;&#xff09;&#xff0c;\u5b9e\u73b0\u4f60\u6307\u5b9a\u7684\u6240\u6709\u63a5\u53e3\u3002\u6bcf\u4e2a\u65b9\u6cd5\u88ab\u8c03\u7528\u65f6\u5b9e\u9645\u8d70\u5230 InvocationHandler.invoke()&#xff0c;\u7531\u4f60\u51b3\u5b9a\u8981\u4e0d\u8981\u8c03\u771f\u5b9e\u5bf9\u8c61\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7cfb\u7edf\u5c5e\u6027 sun.misc.ProxyGenerator.saveGeneratedFiles&#061;true \u628a\u751f\u6210\u7684\u5b57\u8282\u7801 dump \u51fa\u6765\u770b\u770b\u2014\u2014\u6240\u6709\u65b9\u6cd5\u90fd\u8f6c\u53d1\u7ed9\u4e00\u4e2a InvocationHandler&#xff0c;\u800c\u4f60\u7684\u771f\u5b9e\u5bf9\u8c61\u5c31\u5b58\u5728\u8fd9\u4e2a handler \u91cc\u3002<\/p>\n<p>\u800c\u4e14\u6709\u4e00\u4e2a\u5f88\u591a\u4eba\u4e0d\u77e5\u9053\u7684\u7ec6\u8282&#xff1a;\u5982\u679c\u4f60\u540c\u65f6\u5b9e\u73b0\u4e86\u591a\u4e2a\u63a5\u53e3&#xff0c;JDK \u4ee3\u7406\u53ea\u4ee3\u7406\u4f60\u901a\u8fc7 &#064;Autowired \u58f0\u660e\u7684\u90a3\u4e2a\u63a5\u53e3\u7c7b\u578b\u7684\u65b9\u6cd5\u3002\u6bd4\u5982 UserService \u548c Auditable \u4e24\u4e2a\u63a5\u53e3&#xff0c;&#064;Autowired UserService proxy \u53ea\u80fd\u8c03 UserService \u7684\u65b9\u6cd5&#xff0c;\u8c03 Auditable \u7684\u65b9\u6cd5\u8981\u7528 ((Auditable) proxy) \u5f3a\u8f6c\u3002\u4f46\u6ce8\u610f\u2014\u2014\u5f3a\u8f6c\u7684\u524d\u63d0\u662f\u751f\u6210\u7684\u4ee3\u7406\u7c7b\u786e\u5b9e\u5b9e\u73b0\u4e86 Auditable \u63a5\u53e3\u3002\u800c Proxy.newProxyInstance \u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4f60\u4f20\u8fdb\u53bb\u7684\u63a5\u53e3\u6570\u7ec4&#xff0c;\u4f60\u4f20\u4e86 UserService.class \u5c31\u53ea\u751f\u6210\u5b9e\u73b0\u4e86 UserService \u7684\u4ee3\u7406\u7c7b&#xff0c;\u5f3a\u8f6c Auditable \u4f1a\u70b8\u3002\u5fc5\u987b\u628a\u4e24\u4e2a\u63a5\u53e3\u90fd\u4f20\u8fdb\u53bb\u3002\u8fd9\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7ecf\u5e38\u8e29\u5751\u2014\u2014\u4f60\u600e\u4e48\u77e5\u9053 Spring \u5e2e\u4f60\u4f20\u4e86\u54ea\u4e9b\u63a5\u53e3&#xff1f;\u7b54\u6848\u662f Spring \u901a\u8fc7 ClassUtils.getAllInterfaces() \u83b7\u53d6\u76ee\u6807\u7c7b\u7684\u5168\u90e8\u63a5\u53e3&#xff08;\u5305\u62ec\u7236\u63a5\u53e3&#xff09;&#xff0c;\u6240\u4ee5\u53ea\u8981\u63a5\u53e3\u7ee7\u627f\u5173\u7cfb\u5199\u5bf9\u4e86&#xff0c;\u591a\u4e2a\u63a5\u53e3\u90fd\u80fd\u4ee3\u7406\u3002<\/p>\n<hr \/>\n<h3>CGLIB&#xff1a;\u9760\u7ee7\u627f\u2014\u2014\u4ee5\u53ca FastClass \u662f\u4ec0\u4e48\u9b3c<\/h3>\n<p>Enhancer enhancer &#061; new Enhancer();<br \/>\nenhancer.setSuperclass(UserServiceImpl.class);<br \/>\nenhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -&gt; {<br \/>\n    System.out.println(&#034;\u524d\u7f6e\u589e\u5f3a&#034;);<br \/>\n    return proxy.invokeSuper(obj, args);<br \/>\n});<\/p>\n<p>\u5e95\u5c42\u7528 ASM \u6846\u67b6\u751f\u6210\u76ee\u6807\u7c7b\u7684\u5b50\u7c7b\u5b57\u8282\u7801\u3002final \u65b9\u6cd5\u548c final \u7c7b\u65e0\u6cd5\u4ee3\u7406\u2014\u2014CGLIB \u5b50\u7c7b\u62ff\u4e0d\u5230\u7236\u7c7b\u7684 final \u65b9\u6cd5&#xff0c;\u5207\u9762\u4f1a\u9759\u9ed8\u8df3\u8fc7\u4e0d\u62a5\u9519&#xff08;\u6392\u67e5\u5de8\u5751&#xff09;\u3002CGLIB \u7684 invokeSuper \u8d70 FastClass \u7d22\u5f15\u800c\u975e\u53cd\u5c04&#xff0c;\u8c03\u7528\u6027\u80fd\u7406\u8bba\u4e0a\u6bd4 JDK \u4ee3\u7406\u66f4\u9ad8\u3002<\/p>\n<p>\u8bf4&#034;\u7406\u8bba\u4e0a&#034;\u662f\u56e0\u4e3a JDK \u4ee3\u7406\u5728 JVM \u5c42\u9762\u7684\u4f18\u5316\u975e\u5e38\u6fc0\u8fdb\u3002JDK \u4ee3\u7406\u7684 InvocationHandler.invoke() \u8c03\u7528\u5728 JIT \u7f16\u8bd1\u540e\u53ef\u4ee5\u88ab\u5185\u8054\u2014\u2014method.invoke() \u5728\u70ed\u70b9\u4ee3\u7801\u8def\u5f84\u4e0a JVM \u4f1a\u505a\u504f\u5411\u9501\u6d88\u9664\u548c\u53cd\u5c04\u8c03\u7528\u4f18\u5316\u3002CGLIB \u7684 FastClass \u672c\u8d28\u662f\u4e3a\u6bcf\u4e2a\u65b9\u6cd5\u751f\u6210\u4e00\u4e2a\u7d22\u5f15&#xff0c;\u8c03\u7528\u65f6\u901a\u8fc7\u7d22\u5f15\u76f4\u63a5\u8def\u7531\u5230\u76ee\u6807\u65b9\u6cd5&#xff0c;\u907f\u514d\u4e86\u53cd\u5c04\u7684 Method.invoke() \u5f00\u9500\u2014\u2014\u4f46\u5b83\u9700\u8981\u591a\u7ef4\u62a4\u4e00\u5957\u7d22\u5f15\u7c7b\u3002CGLIB \u4f1a\u4e3a\u76ee\u6807\u7c7b\u548c\u4ee3\u7406\u7c7b\u5404\u751f\u6210\u4e00\u4e2a FastClass&#xff1a;\u76ee\u6807\u7c7b\u7684 FastClass \u8d1f\u8d23&#034;\u6839\u636e\u65b9\u6cd5\u7b7e\u540d\u627e\u5230\u7d22\u5f15&#034;&#xff0c;\u4ee3\u7406\u7c7b\u7684 FastClass \u8d1f\u8d23&#034;\u6839\u636e\u7d22\u5f15\u627e\u5230\u5bf9\u5e94\u7684\u62e6\u622a\u5668\u94fe&#034;\u3002<\/p>\n<p>\u4e0d\u8fc7\u8bf4\u771f\u7684&#xff0c;\u5728 JDK 8&#043; \u7684 JIT \u4f18\u5316\u9762\u524d&#xff0c;\u4e24\u8005\u7684\u6027\u80fd\u5dee\u8ddd\u5fae\u4e4e\u5176\u5fae\u3002\u9009 JDK \u4ee3\u7406\u8fd8\u662f CGLIB&#xff0c;\u6027\u80fd\u4e0d\u5e94\u8be5\u6210\u4e3a\u9996\u8981\u7406\u7531\u2014\u2014\u67b6\u6784\u5408\u7406\u6027\u624d\u662f\u3002<\/p>\n<p>CGLIB \u8fd8\u6709\u4e00\u4e2a callback filter \u673a\u5236&#xff08;CallbackFilter&#xff09;&#xff1a;\u4f60\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u65b9\u6cd5\u6307\u5b9a\u4e0d\u540c\u7684\u62e6\u622a\u5668\u3002\u6bd4\u5982 save() \u8d70\u4e8b\u52a1\u4ee3\u7406&#xff0c;find() \u8d70\u7f13\u5b58\u4ee3\u7406\u2014\u2014\u4e00\u4e2a\u4ee3\u7406\u5bf9\u8c61\u80cc\u540e\u6302\u591a\u4e2a CGLIB Callback&#xff0c;\u901a\u8fc7 accept() \u65b9\u6cd5\u8fd4\u56de\u7684\u7d22\u5f15\u6765\u51b3\u5b9a\u8d70\u54ea\u4e2a\u3002Spring \u7684 CglibAopProxy \u5229\u7528\u8fd9\u4e2a\u673a\u5236\u5b9e\u73b0\u4e86&#034;\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u4e0d\u9700\u8981\u4ee3\u7406\u5c31\u8df3\u8fc7\u62e6\u622a\u5668\u76f4\u63a5\u8c03\u7528\u539f\u65b9\u6cd5&#034;\u7684\u4f18\u5316\u3002<\/p>\n<hr \/>\n<h3>Spring \u7684\u4ee3\u7406\u9009\u62e9\u903b\u8f91\u2014\u2014\u6e90\u7801\u4e00\u884c\u884c\u62c6<\/h3>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727074125-6a670ba548ffe.png\" \/><\/p>\n<p>DefaultAopProxyFactory.createAopProxy() \u7684\u89c4\u5219\u975e\u5e38\u7b80\u6d01\u2014\u2014\u5148\u5224\u65ad\u662f\u4e0d\u662f\u63a5\u53e3&#xff1a;<\/p>\n<p>if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {<br \/>\n    return new JdkDynamicAopProxy(config);  \/\/ \u63a5\u53e3\u2192JDK<br \/>\n}<br \/>\nreturn new ObjenesisCglibAopProxy(config);  \/\/ \u5426\u5219\u2192CGLIB<\/p>\n<p>Spring Boot 2.0 \u8d77 spring.aop.proxy-target-class&#061;true&#xff08;\u9ed8\u8ba4&#xff09;&#xff0c;\u503e\u5411\u4e8e\u5f3a\u5236\u8d70 CGLIB\u3002\u4f46\u5982\u679c\u7c7b\u5b9e\u73b0\u4e86\u63a5\u53e3\u4e14\u58f0\u660e\u7684\u662f\u63a5\u53e3\u7c7b\u578b\u800c\u975e\u5b9e\u73b0\u7c7b&#xff0c;Spring \u4ecd\u4f1a\u4f18\u5148 JDK \u4ee3\u7406\u3002\u8fd9\u4e2a\u4f18\u5148\u7ea7\u89c4\u5219\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u9645\u5f00\u53d1\u4e2d\u5f88\u591a\u4eba\u641e\u6df7\u2014\u2014\u4f60 &#064;Autowired UserService&#xff08;\u63a5\u53e3&#xff09;\u548c &#064;Autowired UserServiceImpl&#xff08;\u5b9e\u73b0\u7c7b&#xff09;\u6ce8\u5165\u7684\u4ee3\u7406\u5bf9\u8c61\u7c7b\u578b\u53ef\u80fd\u5b8c\u5168\u4e0d\u540c\u3002<\/p>\n<p>\u6df1\u6316\u4e00\u5c42&#xff1a;\u4e3a\u4ec0\u4e48 Spring \u7528 Objenesis \u800c\u4e0d\u662f\u7b80\u5355\u7684 new&#xff1f;\u56e0\u4e3a CGLIB \u751f\u6210\u7684\u5b50\u7c7b\u4e0d\u4e00\u5b9a\u6709\u65e0\u53c2\u6784\u9020\u5668\u3002\u76ee\u6807\u7c7b\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u6709\u53c2\u6784\u9020\u5668&#xff0c;\u4f20\u7edf\u7684 constructor.newInstance() \u4f1a\u70b8\u3002Objenesis \u7ed5\u8fc7\u4e86\u6784\u9020\u5668\u76f4\u63a5\u521b\u5efa\u5bf9\u8c61\u5b9e\u4f8b\u2014\u2014\u5b83\u6784\u9020\u51fa\u7684\u4ee3\u7406\u5bf9\u8c61\u6784\u9020\u5668\u4ece\u672a\u88ab\u8c03\u7528\u8fc7\u3002\u8fd9\u4e5f\u610f\u5473\u7740\u5982\u679c\u4f60\u5728\u6784\u9020\u5668\u91cc\u653e\u521d\u59cb\u5316\u903b\u8f91&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u4e0d\u4f1a\u6267\u884c\u5b83\u2014\u2014\u53c8\u662f\u4e00\u4e2a\u9759\u9ed8\u5751\u3002<\/p>\n<hr \/>\n<h3>AOP \u901a\u77e5\u94fe\u7684\u6267\u884c\u987a\u5e8f\u2014\u2014\u73af\u7ed5\u901a\u77e5\u5230\u5e95\u5305\u4e86\u4ec0\u4e48<\/h3>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727074125-6a670ba5b0b75.png\" \/><\/p>\n<p>\u9762\u8bd5\u5b98\u5076\u5c14\u4f1a\u95ee&#xff1a;&#034;\u4e94\u4e2a\u901a\u77e5\u7c7b\u578b\u7684\u6267\u884c\u987a\u5e8f\u662f\u4ec0\u4e48&#xff1f;&#034;\u8fd9\u4e0d\u662f\u5728\u8003\u4f60\u8bb0\u5fc6\u529b&#xff0c;\u662f\u5728\u8003\u4f60\u7406\u4e0d\u7406\u89e3 AOP \u7684\u672c\u8d28\u662f&#034;\u6808\u5f0f\u5d4c\u5957\u8c03\u7528&#034;\u3002<\/p>\n<p>\u6267\u884c\u987a\u5e8f\u662f&#xff1a;&#064;Around&#xff08;\u524d\u7f6e\u90e8\u5206&#xff09;\u2192 &#064;Before \u2192 \u76ee\u6807\u65b9\u6cd5 \u2192 &#064;Around&#xff08;\u540e\u7f6e\u90e8\u5206&#xff09;\u2192 &#064;After \u2192 &#064;AfterReturning&#xff08;\u6b63\u5e38\u8fd4\u56de&#xff09;\u6216 &#064;AfterThrowing&#xff08;\u629b\u5f02\u5e38&#xff09;\u3002<\/p>\n<p>\u5173\u952e\u70b9&#xff1a;&#064;After \u65e0\u8bba\u76ee\u6807\u65b9\u6cd5\u6b63\u5e38\u6267\u884c\u8fd8\u662f\u629b\u5f02\u5e38\u90fd\u4f1a\u6267\u884c&#xff0c;\u7c7b\u4f3c\u4e8e try-catch-finally \u4e2d\u7684 finally \u5757\u3002&#064;AfterReturning \u53ea\u5728\u6b63\u5e38\u8fd4\u56de\u65f6\u6267\u884c&#xff0c;&#064;AfterThrowing \u53ea\u5728\u629b\u5f02\u5e38\u65f6\u6267\u884c\u3002<\/p>\n<p>\u53e6\u5916&#xff0c;\u591a\u4e2a\u5207\u9762\u65f6\u7684\u6392\u5e8f\u9760 &#064;Order \u6ce8\u89e3\u6216\u5b9e\u73b0 Ordered \u63a5\u53e3\u3002\u6570\u5b57\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8\u2014\u2014&#064;Order(1) \u7684\u5207\u9762\u5728\u6700\u5916\u5c42&#xff0c;&#064;Order(10) \u7684\u5207\u9762\u5728\u6700\u5185\u5c42\u3002\u8fd9\u548c\u540c\u5fc3\u5706\u4e00\u6837&#xff1a;\u6700\u5916\u5c42\u6700\u5148\u6267\u884c\u524d\u7f6e\u3001\u6700\u540e\u6267\u884c\u540e\u7f6e\u3002<\/p>\n<p>\u9762\u8bd5\u5b98\u53ef\u80fd\u8ffd\u95ee\u7684\u5751&#xff1a;\u5982\u679c &#064;AfterThrowing \u91cc\u53c8\u629b\u4e86\u5f02\u5e38\u4f1a\u600e\u6837&#xff1f; \u5b83\u4f1a\u8986\u76d6\u539f\u59cb\u5f02\u5e38&#xff0c;\u4ee3\u7406\u8fd4\u56de\u7ed9\u8c03\u7528\u65b9\u7684\u5c31\u662f\u4f60 &#064;AfterThrowing \u91cc\u629b\u51fa\u7684\u5f02\u5e38&#xff0c;\u539f\u59cb\u5f02\u5e38\u88ab\u541e\u4e86\u2014\u2014\u6392\u67e5\u7ebf\u4e0a Bug \u65f6\u7ecf\u5e38\u4ee5\u4e3a\u4ee3\u7406\u903b\u8f91\u6ca1\u95ee\u9898&#xff0c;\u7ed3\u679c\u5f02\u5e38\u6808\u88ab\u66ff\u6362\u4e86\u3002<\/p>\n<hr \/>\n<h3>\u9009\u9519\u4f1a\u51fa\u4ec0\u4e48\u4e8b\u6545&#xff1f;<\/h3>\n<p>\u4e8b\u6545\u4e00&#xff1a;JDK \u4ee3\u7406\u5bf9\u8c61\u5f3a\u8f6c\u4e3a\u5b9e\u73b0\u7c7b\u2192ClassCastException\u3002&#064;Autowired UserService&#xff08;\u63a5\u53e3\u7c7b\u578b&#xff09;OK&#xff0c;&#064;Autowired UserServiceImpl&#xff08;\u5b9e\u73b0\u7c7b&#xff09;\u70b8\u3002<\/p>\n<p>\u4e8b\u6545\u4e8c&#xff1a;CGLIB \u4ee3\u7406\u7684\u7c7b\u6709 final \u65b9\u6cd5\u2192\u5207\u9762\u4e0d\u751f\u6548&#xff0c;\u9759\u9ed8\u5931\u8d25\u6392\u67e5\u534a\u5929\u3002\u89c1\u8fc7\u6700\u5751\u7684\u7ebf\u4e0a Bug&#xff1a;&#064;Transactional \u4e0d\u751f\u6548&#xff0c;\u4e09\u5c0f\u65f6\u540e\u53d1\u73b0\u6ce8\u89e3\u52a0\u5728 private \u65b9\u6cd5\u4e0a\u2014\u2014CGLIB \u5b50\u7c7b\u62ff\u4e0d\u5230\u7236\u7c7b private \u65b9\u6cd5&#xff0c;\u5207\u9762\u76f4\u63a5\u8df3\u8fc7\u3002<\/p>\n<p>\u4e8b\u6545\u4e09&#xff1a;\u540c\u4e00\u4e2a Bean \u91cc\u65b9\u6cd5\u81ea\u8c03\u7528 this.methodB()\u2192\u4e0d\u8d70\u4ee3\u7406&#xff0c;\u5207\u9762\u5931\u6548\u3002\u9700\u8981\u7528 AopContext.currentProxy() \u6216\u62c6 Bean \u89e3\u51b3\u3002<\/p>\n<p>\u4e8b\u6545\u56db&#xff08;\u8fd9\u4e2a\u89c1\u8fc7\u66f4\u60e8\u7684&#xff09;&#xff1a;\u6784\u9020\u5668\u6ce8\u5165\u7684\u5faa\u73af\u4f9d\u8d56\u3002A \u9700\u8981 B&#xff0c;B \u9700\u8981 A\u2014\u2014\u6784\u9020\u5668\u6ce8\u5165\u65f6\u53cc\u65b9\u90fd\u9700\u8981\u5bf9\u65b9\u5b8c\u6210\u521d\u59cb\u5316\u624d\u80fd\u6784\u9020\u81ea\u5df1&#xff0c;\u76f4\u63a5\u6b7b\u9501\u3002\u6362\u6210 &#064;Lazy \u6216 setter \u6ce8\u5165\u624d\u80fd\u7ed5\u5f00\u3002\u800c\u4e00\u65e6\u6d89\u53ca\u4ee3\u7406\u5bf9\u8c61\u7684\u5faa\u73af\u4f9d\u8d56&#xff0c;\u573a\u666f\u66f4\u590d\u6742\u2014\u2014\u56e0\u4e3a\u4ee3\u7406\u5bf9\u8c61\u7684\u521b\u5efa\u65f6\u5e8f\u4f1a\u5f71\u54cd\u5faa\u73af\u4f9d\u8d56\u7684\u89e3\u94fe\u3002Spring \u7684\u4e09\u7ea7\u7f13\u5b58&#xff08;singletonFactories&#xff09;\u5c31\u662f\u4e3a\u8fd9\u4e2a\u8bbe\u8ba1\u7684&#xff0c;\u4f46\u5982\u679c\u4f60\u4e0d\u77e5\u9053\u4ee3\u7406\u5bf9\u8c61\u5728\u4e09\u7ea7\u7f13\u5b58\u4e2d\u7684\u5730\u4f4d&#xff0c;\u51fa\u4e86\u5faa\u73af\u4f9d\u8d56\u7684 Bug \u4f60\u53ea\u80fd\u6293\u778e\u3002<\/p>\n<hr \/>\n<h3>Spring AOP vs AspectJ\u2014\u2014\u9762\u8bd5\u5b98\u5728\u7b49\u4f60\u8bf4\u51fa&#034;\u5b83\u4fe9\u4e0d\u662f\u4e00\u4e2a\u4e1c\u897f&#034;<\/h3>\n<p>\u5f88\u591a\u4eba\u9762\u8bd5\u65f6\u8bf4&#034;Spring AOP \u5c31\u662f AspectJ&#034;\u2014\u2014\u8fd9\u662f\u5178\u578b\u7684\u6df7\u6dc6\u3002Spring AOP \u662f\u57fa\u4e8e\u4ee3\u7406\u7684\u8fd0\u884c\u65f6 AOP&#xff0c;\u53ea\u80fd\u5728 Spring \u5bb9\u5668\u7ba1\u7406\u7684 Bean \u4e0a\u751f\u6548\u3002AspectJ \u662f\u7f16\u8bd1\u671f\u7ec7\u5165&#xff0c;\u901a\u8fc7 ajc \u7f16\u8bd1\u5668\u6216\u7c7b\u52a0\u8f7d\u671f\u7ec7\u5165\u628a\u5207\u9762\u903b\u8f91\u76f4\u63a5\u5199\u5165\u5b57\u8282\u7801\u3002<\/p>\n<p>\u6700\u76f4\u89c2\u7684\u533a\u522b&#xff1a;Spring AOP \u53ea\u80fd\u4ee3\u7406 Spring Bean \u7684 public \u65b9\u6cd5&#xff0c;AspectJ \u53ef\u4ee5\u5207\u5165\u4efb\u4f55\u7c7b&#xff08;\u5305\u62ec\u975e Spring \u7ba1\u7406\u7684&#xff09;\u7684\u4efb\u610f\u65b9\u6cd5&#xff08;\u5305\u62ec private&#xff09;\u3002\u4e3a\u4ec0\u4e48&#xff1f;Spring AOP \u9760\u4ee3\u7406\u5bf9\u8c61\u62e6\u622a\u65b9\u6cd5\u8c03\u7528&#xff0c;\u4ee3\u7406\u53ea\u80fd\u8986\u76d6\u5230\u4ee3\u7406\u5bf9\u8c61\u4e0a\u7684\u65b9\u6cd5\u8c03\u7528&#xff1b;AspectJ \u76f4\u63a5\u4fee\u6539\u4e86\u5b57\u8282\u7801&#xff0c;\u65e0\u5dee\u522b\u7ec7\u5165\u3002<\/p>\n<p>\u4f60\u5982\u679c\u60f3\u8ba9 &#064;Transactional \u5728\u540c\u4e00\u4e2a\u7c7b\u7684\u5185\u90e8\u8c03\u7528\u4e2d\u4e5f\u751f\u6548&#xff0c;Spring AOP \u505a\u4e0d\u5230&#xff0c;\u5fc5\u987b\u62c6 Bean \u6216\u7528 AspectJ \u7684 LTW&#xff08;Load-Time Weaving&#xff09;\u3002<\/p>\n<hr \/>\n<h3>&#x1f3af; \u9762\u8bd5\u6807\u51c6\u56de\u7b54<\/h3>\n<p>&#034;Spring AOP \u901a\u8fc7 DefaultAopProxyFactory \u81ea\u52a8\u9009\u62e9\u4ee3\u7406\u65b9\u5f0f\u3002\u76ee\u6807\u7c7b\u5b9e\u73b0\u4e86\u63a5\u53e3\u4e14\u58f0\u660e\u4e3a\u63a5\u53e3\u7c7b\u578b\u2192JDK \u52a8\u6001\u4ee3\u7406&#xff0c;Proxy.newProxyInstance \u8fd0\u884c\u65f6\u751f\u6210\u63a5\u53e3\u5b9e\u73b0\u7c7b\u5b57\u8282\u7801&#xff0c;\u53ea\u80fd\u4ee3\u7406\u63a5\u53e3\u65b9\u6cd5\u3002\u5426\u5219\u2192CGLIB&#xff0c;\u7528 ASM \u751f\u6210\u76ee\u6807\u7c7b\u7684\u5b50\u7c7b\u5b57\u8282\u7801&#xff0c;\u57fa\u4e8e\u7ee7\u627f\u4e0d\u80fd\u4ee3\u7406 final \u65b9\u6cd5\u6216\u7c7b\u3002Spring Boot 2.0 \u9ed8\u8ba4 proxy-target-class&#061;true \u503e\u5411 CGLIB\u3002\u5173\u952e\u5dee\u5f02&#xff1a;JDK \u57fa\u4e8e\u63a5\u53e3\u4e0d\u80fd\u5f3a\u8f6c\u5b9e\u73b0\u7c7b&#xff0c;CGLIB \u57fa\u4e8e\u7ee7\u627f\u4e0d\u80fd\u4ee3\u7406 final \u4e14\u5185\u90e8\u81ea\u8c03\u7528\u4e0d\u8d70\u4ee3\u7406\u3002CGLIB \u7684 invokeSuper \u8d70 FastClass \u7d22\u5f15\u66ff\u4ee3\u53cd\u5c04\u6027\u80fd\u66f4\u9ad8\u3002\u5b9e\u9645\u5f00\u53d1\u4e2d\u6700\u5bb9\u6613\u8e29\u7684\u5751&#xff1a;private \u65b9\u6cd5\u4e0a &#064;Transactional \u9759\u9ed8\u5931\u6548&#xff0c;\u56e0\u4e3a CGLIB \u5b50\u7c7b\u62ff\u4e0d\u5230\u7236\u7c7b\u79c1\u6709\u65b9\u6cd5\u3002\u901a\u77e5\u6267\u884c\u987a\u5e8f\u662f &#064;Around\u2192&#064;Before\u2192\u76ee\u6807\u65b9\u6cd5\u2192&#064;Around\u540e\u7f6e\u2192&#064;After\u2192&#064;AfterReturning\/&#064;AfterThrowing&#xff0c;\u591a\u5207\u9762\u901a\u8fc7 &#064;Order \u63a7\u5236\u4f18\u5148\u7ea7\u3002Spring AOP \u662f\u8fd0\u884c\u65f6\u4ee3\u7406 AOP&#xff0c;\u53ea\u5bf9 Spring \u7ba1\u7406\u7684 Bean \u7684 public \u65b9\u6cd5\u751f\u6548&#xff1b;AspectJ \u662f\u7f16\u8bd1\u671f\u7ec7\u5165&#xff0c;\u53ef\u4ee5\u7ec7\u5165\u4efb\u610f\u7c7b\u7684\u4efb\u610f\u65b9\u6cd5\u3002&#034;<\/p>\n<hr \/>\n<hr \/>\n<h3>AOP \u5931\u6548\u6392\u67e5\u2014\u2014\u9762\u8bd5\u5b98\u6700\u5e38\u73b0\u573a\u51fa\u7684\u9898<\/h3>\n<p>\u9762\u8bd5\u5230\u6700\u540e&#xff0c;\u9762\u8bd5\u5b98\u53ef\u80fd\u4f1a\u73b0\u573a\u7ed9\u4f60\u4e00\u6bb5\u4ee3\u7801\u8ba9\u4f60\u6311 Bug\u3002\u8fd9\u7c7b\u9898\u7684\u6838\u5fc3\u8003\u70b9\u5c31\u4e00\u4e2a&#xff1a;\u4f60\u77e5\u4e0d\u77e5\u9053\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4ee3\u7406\u4e0d\u751f\u6548\u3002<\/p>\n<p>\u6700\u5e38\u89c1\u7684\u5957\u8def\u4ee3\u7801&#xff1a;<\/p>\n<p>&#064;Service<br \/>\npublic class OrderService {<br \/>\n    &#064;Transactional<br \/>\n    public void createOrder(Order order) {<br \/>\n        \/\/ \u5199\u8ba2\u5355<br \/>\n        this.sendNotification(order);  \/\/ \u8fd9\u91cc\u7684 &#064;Transactional \u4e0d\u4f1a\u751f\u6548&#xff01;<br \/>\n    }<\/p>\n<p>    &#064;Transactional(propagation &#061; Propagation.REQUIRES_NEW)<br \/>\n    public void sendNotification(Order order) {<br \/>\n        \/\/ \u53d1\u901a\u77e5<br \/>\n    }<br \/>\n}<\/p>\n<p>createOrder() \u91cc\u7684 this.sendNotification() \u4e0d\u8d70\u4ee3\u7406\u2014\u2014\u56e0\u4e3a this \u662f OrderService \u672c\u8eab&#xff0c;\u4e0d\u662f\u4ee3\u7406\u5bf9\u8c61\u3002\u4f60\u8c03 this.sendNotification() \u76f8\u5f53\u4e8e\u76f4\u63a5\u8c03\u539f\u59cb\u5bf9\u8c61\u7684 sendNotification()&#xff0c;CGLIB \u90a3\u5c42\u62e6\u622a\u5668\u6839\u672c\u6ca1\u673a\u4f1a\u8fd0\u884c\u3002REQUIRES_NEW \u4e5f\u4e0d\u4f1a\u751f\u6548\u2014\u2014\u4e24\u4e2a\u65b9\u6cd5\u4f1a\u5728\u540c\u4e00\u4e2a\u4e8b\u52a1\u91cc\u6267\u884c\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u5f0f\u6709\u4e09\u79cd&#xff1a;\u4e00\u662f\u62c6\u6210\u4e24\u4e2a Bean&#xff0c;\u7528 &#064;Autowired \u6ce8\u5165\u81ea\u5df1&#xff1b;\u4e8c\u662f\u7528 AopContext.currentProxy() \u83b7\u53d6\u5f53\u524d\u4ee3\u7406\u5bf9\u8c61\u540e\u518d\u8c03&#xff1b;\u4e09\u662f\u5728\u914d\u7f6e\u7c7b\u4e0a\u52a0 &#064;EnableAspectJAutoProxy(exposeProxy &#061; true)&#xff0c;\u7136\u540e ((OrderService) AopContext.currentProxy()).sendNotification(order)\u3002<\/p>\n<p>\u9762\u8bd5\u5b98\u5982\u679c\u518d\u8ffd\u95ee&#034;AopContext.currentProxy() \u7684\u539f\u7406\u662f\u4ec0\u4e48&#034;\u2014\u2014\u5b83\u662f\u901a\u8fc7 ThreadLocal \u628a\u5f53\u524d\u4ee3\u7406\u5bf9\u8c61\u7ed1\u5b9a\u5230\u7ebf\u7a0b\u4e0a&#xff0c;\u5728\u4ee3\u7406\u65b9\u6cd5\u6267\u884c\u524d\u8bbe\u7f6e\u3001\u6267\u884c\u540e\u6e05\u9664\u3002\u6240\u4ee5\u5b83\u53ea\u80fd\u5728\u4ee3\u7406\u5bf9\u8c61\u7684\u67d0\u4e2a\u65b9\u6cd5\u6b63\u5728\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\u4f7f\u7528&#xff0c;\u8131\u79bb\u4e86\u4ee3\u7406\u65b9\u6cd5\u7684\u8c03\u7528\u94fe\u62ff\u5230\u7684\u662f null\u3002<\/p>\n<p>\u53e6\u5916\u8865\u5145\u4e24\u4e2a\u6392\u67e5 AOP \u5931\u6548\u7684\u6377\u5f84&#xff1a;\u7b2c\u4e00&#xff0c;\u542f\u52a8\u65f6\u6253 debug \u65e5\u5fd7\u770b AbstractAutoProxyCreator \u7684 advisor \u5339\u914d\u60c5\u51b5\u2014\u2014Spring \u4f1a\u5728\u65e5\u5fd7\u91cc\u544a\u8bc9\u4f60\u67d0\u4e2a Bean \u88ab\u4ee3\u7406\u4e86\u8fd8\u662f\u6ca1\u6709\u5339\u914d\u5230\u5207\u5165\u70b9&#xff1b;\u7b2c\u4e8c&#xff0c;\u6253\u65ad\u70b9\u5728 CglibAopProxy \u7684 getProxy() \u65b9\u6cd5&#xff0c;\u76f4\u63a5\u770b\u8fd4\u56de\u5bf9\u8c61\u7684\u7c7b\u578b\u2014\u2014\u662f\u539f\u59cb\u7c7b\u8fd8\u662f $$EnhancerBySpringCGLIB \u7ed3\u5c3e\u7684\u4ee3\u7406\u7c7b&#xff0c;\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<hr \/>\n<p>\u5520\u70b9\u952e\u76d8\u4e4b\u5916\u7684&#xff1a;<\/p>\n<p>8 \u5e74\u5927\u5382 Java \u8001\u5175&#xff0c;\u4e0d\u8bb2\u516b\u80a1\u6587&#xff0c;\u53ea\u8bb2\u9762\u8bd5\u5b98\u5fc3\u91cc\u5728\u60f3\u4ec0\u4e48\u3002\u4e0b\u4e00\u7bc7\u6587\u7ae0\u6211\u4eec\u804a\u4e00\u4e2a\u66f4\u5e95\u5c42\u7684\u8bdd\u9898\u2014\u2014\u5f53\u4f60\u8ba4\u4e3a\u4e00\u4e2a Bug \u662f\u6846\u67b6\u7684\u95ee\u9898\u65f6&#xff0c;\u5176\u5b9e\u5f80\u5f80\u662f\u4f60\u8fd8\u4e0d\u591f\u4e86\u89e3\u5b83\u7684\u5e95\u5c42\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u5256\u6790 Spring AOP \u7684\u4ee3\u7406\u673a\u5236&#xff0c;\u4ece JDK \u52a8\u6001\u4ee3\u7406\u4e0e CGLIB \u7684\u672c\u8d28\u5dee\u5f02\u3001Spring \u7684\u4ee3\u7406\u9009\u62e9\u903b\u8f91\u3001AOP \u901a\u77e5\u94fe\u6267\u884c\u987a\u5e8f&#xff0c;\u5230\u5e38\u89c1\u4ee3\u7406\u5931\u6548\u573a\u666f\u4e0e\u6392\u67e5\u65b9\u6cd5\u3002\u6587\u7ae0\u4e0d\u4ec5\u5bf9\u6bd4\u4e86\u4e24\u79cd\u4ee3\u7406\u65b9\u5f0f\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u6027\u80fd\u8003\u91cf&#xff0c;\u8fd8\u7ed3\u5408\u6e90\u7801\u89e3\u8bfb\u4e86 Spring \u7684\u4ee3\u7406\u4f18\u5148\u7ea7\u89c4\u5219&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u9762\u8bd5\u6807\u51c6\u56de\u7b54\u4e0e\u5b9e\u6218\u907f\u5751\u6307\u5357&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5f7b\u5e95\u7406\u89e3 AOP \u4ee3\u7406\u7684\u5e95\u5c42\u884c\u4e3a\u4e0e\u6700\u4f73\u5b9e\u8df5\u3002\u9762\u8bd5\u95ee Spring A<\/p>\n","protected":false},"author":2,"featured_media":85460,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,101,292],"topic":[],"class_list":["post-85463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-spring","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/85463.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u5256\u6790 Spring AOP \u7684\u4ee3\u7406\u673a\u5236&#xff0c;\u4ece JDK \u52a8\u6001\u4ee3\u7406\u4e0e CGLIB \u7684\u672c\u8d28\u5dee\u5f02\u3001Spring \u7684\u4ee3\u7406\u9009\u62e9\u903b\u8f91\u3001AOP \u901a\u77e5\u94fe\u6267\u884c\u987a\u5e8f&#xff0c;\u5230\u5e38\u89c1\u4ee3\u7406\u5931\u6548\u573a\u666f\u4e0e\u6392\u67e5\u65b9\u6cd5\u3002\u6587\u7ae0\u4e0d\u4ec5\u5bf9\u6bd4\u4e86\u4e24\u79cd\u4ee3\u7406\u65b9\u5f0f\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u6027\u80fd\u8003\u91cf&#xff0c;\u8fd8\u7ed3\u5408\u6e90\u7801\u89e3\u8bfb\u4e86 Spring \u7684\u4ee3\u7406\u4f18\u5148\u7ea7\u89c4\u5219&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u9762\u8bd5\u6807\u51c6\u56de\u7b54\u4e0e\u5b9e\u6218\u907f\u5751\u6307\u5357&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5f7b\u5e95\u7406\u89e3 AOP \u4ee3\u7406\u7684\u5e95\u5c42\u884c\u4e3a\u4e0e\u6700\u4f73\u5b9e\u8df5\u3002\u9762\u8bd5\u95ee Spring A\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/85463.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-27T07:41:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727074124-6a670ba4e040a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85463.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/85463.html\",\"name\":\"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-27T07:41:27+00:00\",\"dateModified\":\"2026-07-27T07:41:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/85463.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/85463.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85463.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/85463.html","og_locale":"zh_CN","og_type":"article","og_title":"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u5256\u6790 Spring AOP \u7684\u4ee3\u7406\u673a\u5236&#xff0c;\u4ece JDK \u52a8\u6001\u4ee3\u7406\u4e0e CGLIB \u7684\u672c\u8d28\u5dee\u5f02\u3001Spring \u7684\u4ee3\u7406\u9009\u62e9\u903b\u8f91\u3001AOP \u901a\u77e5\u94fe\u6267\u884c\u987a\u5e8f&#xff0c;\u5230\u5e38\u89c1\u4ee3\u7406\u5931\u6548\u573a\u666f\u4e0e\u6392\u67e5\u65b9\u6cd5\u3002\u6587\u7ae0\u4e0d\u4ec5\u5bf9\u6bd4\u4e86\u4e24\u79cd\u4ee3\u7406\u65b9\u5f0f\u7684\u5b9e\u73b0\u539f\u7406\u4e0e\u6027\u80fd\u8003\u91cf&#xff0c;\u8fd8\u7ed3\u5408\u6e90\u7801\u89e3\u8bfb\u4e86 Spring \u7684\u4ee3\u7406\u4f18\u5148\u7ea7\u89c4\u5219&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u9762\u8bd5\u6807\u51c6\u56de\u7b54\u4e0e\u5b9e\u6218\u907f\u5751\u6307\u5357&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5f7b\u5e95\u7406\u89e3 AOP \u4ee3\u7406\u7684\u5e95\u5c42\u884c\u4e3a\u4e0e\u6700\u4f73\u5b9e\u8df5\u3002\u9762\u8bd5\u95ee Spring A","og_url":"https:\/\/www.wsisp.com\/helps\/85463.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-27T07:41:27+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260727074124-6a670ba4e040a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/85463.html","url":"https:\/\/www.wsisp.com\/helps\/85463.html","name":"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-27T07:41:27+00:00","dateModified":"2026-07-27T07:41:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/85463.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/85463.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/85463.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"15 \u9762\u8bd5\u5b98\uff1aSpring AOP \u7528 JDK \u4ee3\u7406\u8fd8\u662f CGLIB\uff1f\u4f60\u7b54\u5bf9\u4e86\u4f46\u6ca1\u8bf4\u4e3a\u4ec0\u4e48"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/85463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=85463"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/85463\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/85460"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=85463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=85463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=85463"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=85463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}