{"id":903,"date":"2023-05-28T02:11:04","date_gmt":"2023-05-27T18:11:04","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=903"},"modified":"2023-05-28T02:11:04","modified_gmt":"2023-05-27T18:11:04","slug":"spring-14-aop-cglib-%e4%bb%a3%e7%90%86%e5%af%b9%e8%b1%a1%e6%ba%90%e7%a0%81","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-14-aop-cglib-%e4%bb%a3%e7%90%86%e5%af%b9%e8%b1%a1%e6%ba%90%e7%a0%81\/","title":{"rendered":"Spring-14 AOP CGLIB \u4ee3\u7406\u5bf9\u8c61\u6e90\u7801"},"content":{"rendered":"<div class='wxsyncmain'>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"font-size: 16px;color: black;padding: 0 10px;line-height: 1.6;word-spacing: 0px;letter-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#39;PingFang SC&#39;, Cambria, Cochin, Georgia, Times, &#39;Times New Roman&#39;, serif;\">\n<section><mp-common-profile class=\"js_uneditable custom_select_card mp_profile_iframe\" data-pluginname=\"mpprofile\" data-weui-theme=\"light\" data-id=\"MzU5MTg2OTc3Ng==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/fY4QmJ5a6icHwnQcJNnBTVFbO7UAHRzibLgEmunvgVcWlmluVpicdNkGAiaNROH9RqVgInCazzkMUJQ5OEhdcGvwwA\/0?wx_fmt=png\" data-nickname=\"DevXJava\" data-alias=\"DevXJava\" data-signature=\"Java\u6280\u672f\u5206\u4eab\" data-from=\"0\" data-is_biz_ban=\"0\"><\/mp-common-profile><\/section>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.5291005291005291\"  data-type=\"jpeg\" data-w=\"567\" style=\"display: block;margin: 0 auto;max-width: 100%;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.5291005291005291\"  data-type=\"jpeg\" data-w=\"567\" style=\"display: block;margin: 0 auto;max-width: 100%;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg\"><\/noscript><figcaption style=\"margin-top: 5px;text-align: center;color: #888;font-size: 14px;\"><br  \/><\/figcaption><\/figure>\n<h1 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 24px;\"><span style=\"display: none;\"><\/span><span>Spring-14 AOP CGLIB \u4ee3\u7406\u5bf9\u8c61\u6e90\u7801<\/span><span><\/span><\/h1>\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;\">Spring \u6e90\u7801\u7cfb\u5217\u6587\u7ae0\u4f1a\u9075\u5faa\u7531\u6d45\u5165\u6df1,\u7531\u6613\u5230\u96be,\u7531\u5b8f\u89c2\u5230\u5fae\u89c2\u7684\u539f\u5219,\u76ee\u6807\u662f\u5c3d\u91cf\u964d\u4f4e\u5b66\u4e60\u96be\u5ea6,\u800c\u4e0d\u662f\u4e00\u4e0a\u6765\u5c31\u8ff7\u5931\u5728\u6e90\u7801\u5f53\u4e2d. \u6587\u7ae0\u4f1a\u4ece\u4e00\u4e2a\u573a\u666f\u4f5c\u4e3a\u51fa\u53d1\u70b9\uff0c\u9488\u5bf9\u6027\u7684\u76ee\u7684\u6027\u6781\u5f3a\u7684\u9488\u5bf9\u8be5\u573a\u666f\u5bf9 Spring \u7684\u5b9e\u73b0\u539f\u7406\uff0c\u6e90\u7801\u8fdb\u884c\u63a2\u7a76\u5b66\u4e60\u3002\u8be5\u7cfb\u5217\u6587\u7ae0\u4f1a\u8ba9\u4f60\u6536\u83b7\u4ec0\u4e48? \u4ece\u5bf9 Spring \u7684\u4f7f\u7528\u8005\u6210\u4e3a Spring \u4e13\u5bb6\u3002\u8be5\u6587\u7ae0\u4f1a\u540c\u6b65\u5728\u5fae\u4fe1\u516c\u4f17\u53f7 \u3010DevXJava\u3011, \u65b9\u4fbf\u5728\u5fae\u4fe1\u5ba2\u6237\u7aef\u9605\u8bfb\u3002<\/p>\n<\/blockquote>\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"border-top: none;border-right: none;border-bottom: none;display: block;font-size: 0.9em;overflow: auto;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0px;color: black;line-height: 26px;\">\u672c\u7ae0\u4f1a\u4ecb\u7ecd <code style=\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\">AOP<\/code> \u751f\u6210\u7684\u4ee3\u7406\u5bf9\u8c61\u6e90\u7801\uff0c\u8ba9\u8bfb\u8005\u66f4\u52a0\u6e05\u6670\u7684\u8ba4\u8bc6 spring AOP \u521b\u5efa\u7684\u4ee3\u7406\u5bf9\u8c61\u3002<\/p>\n<\/blockquote>\n<h5 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;padding: 0px;font-weight: bold;color: black;font-size: 16px;\"><span style=\"display: none;\"><\/span><span>\u573a\u666f<\/span><span style=\"display: none;\"><\/span><\/h5>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background: url(&quot;https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020623535.jpeg&quot;) 10px 10px \/ 40px no-repeat rgb(40, 44, 52);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;\"><\/span><code style=\"overflow-x: auto;padding: 16px;color: #abb2bf;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #282c34;border-radius: 5px;\">private Callback[] getCallbacks(Class&lt;?&gt; rootClass) throws Exception {<br  \/>   \/\/ Parameters used for optimization choices...<br  \/>   boolean exposeProxy = this.advised.isExposeProxy();<br  \/>   boolean isFrozen = this.advised.isFrozen();<br  \/>   boolean isStatic = this.advised.getTargetSource().isStatic();<br  \/><br  \/>   \/\/ Choose an \"aop\" interceptor (used for AOP calls).<br  \/>   Callback aopInterceptor = new DynamicAdvisedInterceptor(this.advised);<br  \/><br  \/>   \/\/ Choose a \"straight to target\" interceptor. (used for calls that are<br  \/>   \/\/ unadvised but can return this). May be required to expose the proxy.<br  \/>   Callback targetInterceptor;<br  \/>   if (exposeProxy) {<br  \/>      targetInterceptor = (isStatic ?<br  \/>            new StaticUnadvisedExposedInterceptor(this.advised.getTargetSource().getTarget()) :<br  \/>            new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource()));<br  \/>   }<br  \/>   else {<br  \/>      targetInterceptor = (isStatic ?<br  \/>            new StaticUnadvisedInterceptor(this.advised.getTargetSource().getTarget()) :<br  \/>            new DynamicUnadvisedInterceptor(this.advised.getTargetSource()));<br  \/>   }<br  \/><br  \/>   \/\/ Choose a \"direct to target\" dispatcher (used for<br  \/>   \/\/ unadvised calls to static targets that cannot return this).<br  \/>   Callback targetDispatcher = (isStatic ?<br  \/>         new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp());<br  \/><br  \/>   Callback[] mainCallbacks = new Callback[] {<br  \/>         aopInterceptor,  \/\/ for normal advice<br  \/>         targetInterceptor,  \/\/ invoke target without considering advice, if optimized<br  \/>         new SerializableNoOp(),  \/\/ no override for methods mapped to this<br  \/>         targetDispatcher, this.advisedDispatcher,<br  \/>         new EqualsInterceptor(this.advised),<br  \/>         new HashCodeInterceptor(this.advised)<br  \/>   };<br  \/><br  \/>   Callback[] callbacks;<br  \/><br  \/>   \/\/ If the target is a static one and the advice chain is frozen,<br  \/>   \/\/ then we can make some optimizations by sending the AOP calls<br  \/>   \/\/ direct to the target using the fixed chain for that method.<br  \/>   if (isStatic &amp;&amp; isFrozen) {<br  \/>      Method[] methods = rootClass.getMethods();<br  \/>      Callback[] fixedCallbacks = new Callback[methods.length];<br  \/>      this.fixedInterceptorMap = CollectionUtils.newHashMap(methods.length);<br  \/><br  \/>      \/\/ TODO: small memory optimization here (can skip creation for methods with no advice)<br  \/>      for (int x = 0; x &lt; methods.length; x++) {<br  \/>         Method method = methods[x];<br  \/>         List&lt;Object&gt; chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, rootClass);<br  \/>         fixedCallbacks[x] = new FixedChainStaticTargetInterceptor(<br  \/>               chain, this.advised.getTargetSource().getTarget(), this.advised.getTargetClass());<br  \/>         this.fixedInterceptorMap.put(method, x);<br  \/>      }<br  \/><br  \/>      \/\/ Now copy both the callbacks from mainCallbacks<br  \/>      \/\/ and fixedCallbacks into the callbacks array.<br  \/>      callbacks = new Callback[mainCallbacks.length + fixedCallbacks.length];<br  \/>      System.arraycopy(mainCallbacks, 0, callbacks, 0, mainCallbacks.length);<br  \/>      System.arraycopy(fixedCallbacks, 0, callbacks, mainCallbacks.length, fixedCallbacks.length);<br  \/>      this.fixedInterceptorOffset = mainCallbacks.length;<br  \/>   }<br  \/>   else {<br  \/>      callbacks = mainCallbacks;<br  \/>   }<br  \/>   return callbacks;<br  \/>}<br  \/><\/code><\/pre>\n<hr data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"height: 1px;margin: 10px 0px;border-right: none;border-bottom: none;border-left: none;border-top: 1px solid black;\"  \/>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;margin: 0;line-height: 26px;color: black;\"><code style=\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\">DevX<\/code> \u4f1a\u6301\u7eed\u5206\u4eab <code style=\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\">Java<\/code> \u6280\u672f\u5e72\u8d27\uff0c\u5982\u679c\u4f60\u89c9\u5f97\u672c\u6587\u5bf9\u4f60\u6709\u5e2e\u52a9\u5e0c\u671b\u4f60\u53ef\u4ee5\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u670b\u53cb\u770b\u5230\u3002\u8be5\u6587\u7ae0\u4f1a\u540c\u6b65\u5728\u5fae\u4fe1\u516c\u4f17\u53f7 \u3010DevXJava\u3011, \u65b9\u4fbf\u5728\u5fae\u4fe1\u5ba2\u6237\u7aef\u9605\u8bfb\u3002<\/p>\n<p style=\"text-align: center;\"><strong style=\"font-weight: bold;color: black;\">DevX \u4e0d\u6b62\u4e8e\u6280\u672f<\/strong><\/p>\n<p><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"1\"  data-type=\"jpeg\" data-w=\"258\" style=\"display: block;margin: 0px auto;max-width: 100%;width: 161px;height: 161px;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020622873.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"1\"  data-type=\"jpeg\" data-w=\"258\" style=\"display: block;margin: 0px auto;max-width: 100%;width: 161px;height: 161px;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020622873.jpeg\"><\/noscript> <\/p>\n<\/section>\n<p><br  \/><\/p>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 DevXJava              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>Spring-14 AOP CGLIB \u4ee3\u7406\u5bf9\u8c61\u6e90\u7801 Spring \u6e90\u7801\u7cfb\u5217\u6587\u7ae0\u4f1a\u9075\u5faa\u7531\u6d45\u5165\u6df1,\u7531\u6613\u5230\u96be,\u7531\u5b8f\u89c2\u5230\u5fae\u89c2\u7684\u539f\u5219,\u76ee\u6807 &#8230;<\/p>\n","protected":false},"author":2,"featured_media":899,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020620916.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020621513.jpeg","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020622873.jpeg","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528020622873.jpeg","id":"image3"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2023-05-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":339,"next_post_id":1005,"next_post_title":"\u6570\u636e\u5e93\u94fe\u63a5\u6c60\u7ec8\u4e8e\u641e\u5bf9\u4e86\uff0c\u8fd9\u6b21\u76f4\u63a5\u4ece100ms\u4f18\u5316\u52303ms\uff01","previous_post_id":917,"previous_post_title":"Spring-15 Spring Certified Professional \u8bd5\u9898\u6574\u7406 \u2460","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=903"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/899"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}