{"id":4195,"date":"2019-04-30T18:17:37","date_gmt":"2019-04-30T10:17:37","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4195"},"modified":"2019-04-30T18:17:37","modified_gmt":"2019-04-30T10:17:37","slug":"%e4%bb%8e%e6%a0%b9%e4%b8%8a%e7%90%86%e8%a7%a3%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%a0%e7%9a%84-transational-%e6%b3%a8%e8%a7%a3%e5%a4%b1%e6%95%88%e4%ba%86","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4195","title":{"rendered":"\u4ece\u6839\u4e0a\u7406\u89e3\u4e3a\u4ec0\u4e48\u4f60\u7684 @Transational \u6ce8\u89e3\u5931\u6548\u4e86"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u9762\u8bd5\u4e2d\uff0c\u5f88\u591a\u4eba\u53ef\u80fd\u90fd\u4f1a\u88ab\u95ee\u5230\u201c@Transational \u6ce8\u89e3\u5931\u6548\u4e86\uff0c\u53ef\u80fd\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u201d\u8fd9\u7c7b\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f51\u4e0a\u6709\u5f88\u591a\u7b54\u6848\u3002\u6bd4\u5982\uff0c@Transational \u53ea\u80fd\u4f5c\u7528\u5728 public \u65b9\u6cd5\u4e0a\u3002\u518d\u6bd4\u5982\uff0c\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u4e00\u4e2a nan-transactional \u7684\u65b9\u6cd5\u53bb\u8c03\u7528  transactional \u7684\u65b9\u6cd5\uff0c\u4e8b\u52a1\u4e5f\u4f1a\u5931\u6548\u7b49\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g2ktqy14scj20ec0fx41p.jpg\" alt=\"\" \/><figcaption>@Transational \u6ce8\u89e3\u5931\u6548\uff0c\u4f60\u6ca1\u5f97\u9009\u62e9<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5b9e\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0d\u4ec5\u56f0\u60d1\u7740\u4f60\u4eec\uff0cstackoverflow \u4e0a\u4e5f\u975e\u5e38\u7684\u70ed\u95e8\u3002\u6211\u603b\u7ed3\u4e00\u4e0b\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4e0b\u9762\u7684\u65b9\u5f0f\u8fdb\u884c\u6392\u67e5\u4f60\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>@Transactional \u52a0\u4e8eprivate\u65b9\u6cd5\uff0c\u65e0\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u672a\u52a0\u5165\u63a5\u53e3\u7684public\u65b9\u6cd5, \u518d\u901a\u8fc7\u666e\u901a\u63a5\u53e3\u65b9\u6cd5\u8c03\u7528\uff0c\u65e0\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u63a5\u53e3\u65b9\u6cd5\uff0c\u65e0\u8bba\u4e0b\u9762\u8c03\u7528\u7684\u662fprivate\u6216public\u65b9\u6cd5\uff0c\u90fd\u6709\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u63a5\u53e3\u65b9\u6cd5\u540e\uff0c\u88ab\u672c\u7c7b\u666e\u901a\u63a5\u53e3\u65b9\u6cd5\u76f4\u63a5\u8c03\u7528\uff0c\u65e0\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u63a5\u53e3\u65b9\u6cd5\u540e\uff0c\u88ab\u672c\u7c7b\u666e\u901a\u63a5\u53e3\u65b9\u6cd5\u901a\u8fc7\u63a5\u53e3\u8c03\u7528\uff0c\u6709\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u63a5\u53e3\u65b9\u6cd5\u540e\uff0c\u88ab\u5b83\u7c7b\u7684\u63a5\u53e3\u65b9\u6cd5\u8c03\u7528\uff0c\u6709\u6548 <\/li><li>@Transactional \u52a0\u4e8e\u63a5\u53e3\u65b9\u6cd5\u540e\uff0c\u88ab\u5b83\u7c7b\u7684\u79c1\u6709\u65b9\u6cd5\u8c03\u7528\u540e\uff0c\u6709\u6548 <\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Transactional \u662f\u5426\u751f\u6548\uff0c\u4ec5\u53d6\u51b3\u4e8e\u662f\u5426\u52a0\u8f7d\u4e8e\u63a5\u53e3\u65b9\u6cd5\uff0c\u5e76\u4e14\u662f\u5426\u901a\u8fc7\u63a5\u53e3\u65b9\u6cd5\u8c03\u7528(\u800c\u4e0d\u662f\u672c\u7c7b\u8c03\u7528)\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\u5462\uff1f\u6211\u4eca\u5929\u7b80\u5355\u7684\u4ece\u4ee3\u7406\u7684\u89d2\u5ea6\u7ed9\u5927\u5bb6\u8bb2\u4e00\u8bb2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">@Transactional \u5931\u6548\u7684\u80cc\u540e\u5176\u5b9e\u5c31\u662f Spring \u4ee3\u7406\u673a\u5236\u9020\u6210\u7684\u3002\u8bf4\u767d\u4e86\uff0c\u5c31\u662f\u901a\u8fc7 Spring \u5bb9\u5668\u83b7\u53d6\u7684\u7c7b\u5bf9\u8c61\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u5e76\u4e0d\u662f\u539f\u7c7b\uff0c\u800c\u662f\u88ab Spring \u4fee\u9970\u8fc7\u4e86\u7684\u4ee3\u7406\u7c7b\u3002\u7136\u540e\uff0c\u4f60\u5728\u88ab\u4ee3\u7406\u7684\u65b9\u6cd5\u4e2d\u8c03\u7528\u5f53\u524d\u7c7b\u7684\u5176\u5b83\u65b9\u6cd5\uff0c\u6b64\u65f6\u5c31\u662f\u8c03\u7528\u7684\u539f\u751f\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u542c\u4e0d\u61c2\u6ca1\u5173\u7cfb\uff0c\u6211\u4e0b\u9762\u7528\u4f2a\u4ee3\u7801\u7ed9\u4f60\u6f14\u793a\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u73b0\u5728\u8981\u6267\u884c Xttblog \u7c7b\u5bf9\u8c61\u7684\u65b9\u6cd5 invoke()\uff0c\u800c\u7528 Spring \u4ee3\u7406\u540e\uff0c\u4f1a\u5bf9 Xttblog \u7c7b\u505a\u4fee\u9970\uff0c\u4e5f\u5c31\u662f\u4f1a\u5bf9 Xttblog \u7684 test \u65b9\u6cd5\u751f\u6210\u4e00\u4e2a\u4ee3\u7406\u7c7b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6267\u884c\uff0c\u8c03\u7528\u4ee3\u7406\u65b9\u6cd5 proxyXttblogbean.invoke():\n\nbefore \u64cd\u4f5c\ninvoke(bean,Xttblog)\nafter \u64cd\u4f5c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u9645\u4f60\u8fd0\u884c\u7684\u662f Spring \u4fee\u9970\u8fc7\u7684\u4ee3\u7406\u7c7b proxyXttblogbean.invoke()\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\u5c31\u4f1a\u9020\u6210\u4e00\u4e2a\u95ee\u9898\uff0c\u5982\u679c\u4f60\u5728 invoke() \u4e2d\u8c03\u7528 Xttblog \u7c7b\u7684\u5176\u4f59\u65b9\u6cd5 invoke2()\uff0c\u6b64\u65f6 invoke2() \u662f\u76f4\u63a5\u8c03\u7528\u7684\u539f\u7c7b\u7684 Xttblog.invoke2()\uff0c\u800c\u4e0d\u662f\u4ee3\u7406\u7c7b proxyXttblogbean.invoke2()\u3002\u8fd9\u65f6 Xttblog.invoke2() \u4e0a\u7684\u4e00\u4e9b\u6ce8\u89e3\u5168\u90e8\u90fd\u6ca1\u6709\u88ab\u589e\u5f3a\u4fee\u9970\u3002\u6240\u4ee5\uff0c\u6700\u7ec8\u7684\u7ed3\u679c\u5c31\u548c\u4f60\u7684\u9884\u671f\u4e0d\u4e00\u81f4\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u6839\u4e0a\u77e5\u9053\u4e86\u53d1\u751f\u8fd9\u7c7b\u95ee\u9898\u7684\u539f\u56e0\uff0c\u95ee\u9898\u5c31\u597d\u89e3\u51b3\u4e86\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u60f3\u529e\u6cd5\u624b\u52a8\u62ff\u5230\u4ee3\u7406\u5bf9\u8c61\u3002\u7c7b\u4f3c\u4e0b\u9762\u7684\u4f2a\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5728invoke()\u65b9\u6cd5\u5185\u90e8\u8c03\u7528invoke2()\u65b9\u6cd5\n\/\/ 1.\u76f4\u63a5\u8c03\u7528invoke2()\uff0c\u6ce8\u89e3\u5931\u6548\u3002\ninvoke2()\n\/\/ 2.\u62ff\u5230\u4ee3\u7406\u7c7b\u5bf9\u8c61\uff0c\u518d\u8c03\u7528invoke2()\u3002\n((Xttblog)AopContext.currentProxy()).invoke2()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u81f3\u4e8e private \u65b9\u6cd5\u4e0a\u7684\u6ce8\u89e3\u4e5f\u5931\u6548\uff0c\u539f\u56e0\u4e5f\u5f88\u7b80\u5355\u3002\u56e0\u4e3a Spring \u4e0d\u7ba1\u4f7f\u7528\u7684\u662f JDK \u52a8\u6001\u4ee3\u7406\u8fd8\u662f CGLIB \u52a8\u6001\u4ee3\u7406\uff0c\u4e00\u4e2a\u662f\u9488\u5bf9\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\uff0c\u4e00\u4e2a\u662f\u901a\u8fc7\u5b50\u7c7b\u5b9e\u73b0\u3002\u65e0\u8bba\u662f\u63a5\u53e3\u8fd8\u662f\u7236\u7c7b\uff0c\u663e\u7136\u90fd\u4e0d\u80fd\u51fa\u73b0 private \u65b9\u6cd5\uff0c\u5426\u5219\u5b50\u7c7b\u6216\u5b9e\u73b0\u7c7b\u90fd\u4e0d\u80fd\u8986\u76d6\u5230\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u65b9\u6cd5\u4e3a private\uff0c\u90a3\u4e48\u5728\u4ee3\u7406\u8fc7\u7a0b\u4e2d\uff0c\u6839\u672c\u627e\u4e0d\u5230\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5f15\u8d77\u4ee3\u7406\u5bf9\u8c61\u521b\u5efa\u51fa\u73b0\u95ee\u9898\uff0c\u4e5f\u5bfc\u81f4\u4e86\u6709\u7684\u5bf9\u8c61\u6ca1\u6709\u6ce8\u5165\u8fdb\u53bb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e94\u4e00\u653e\u5047\u4e86\uff0c\u795d\u5927\u5bb6\u4e94\u4e00\u5feb\u4e50\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4195\">\u4ece\u6839\u4e0a\u7406\u89e3\u4e3a\u4ec0\u4e48\u4f60\u7684 @Transational \u6ce8\u89e3\u5931\u6548\u4e86<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728\u9762\u8bd5\u4e2d\uff0c\u5f88\u591a\u4eba\u53ef\u80fd\u90fd\u4f1a\u88ab\u95ee\u5230\u201c@Transational \u6ce8\u89e3\u5931\u6548\u4e86\uff0c\u53ef\u80fd\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u201d\u8fd9\u7c7b\u95ee\u9898\u3002 \u7f51\u4e0a\u6709\u5f88 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1965,551,1041,1042,1330],"class_list":["post-4195","post","type-post","status-publish","format-standard","hentry","category-java","tag-cglib","tag-spring","tag-1041","tag-ip","tag-1330"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4195"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4195\/revisions"}],"predecessor-version":[{"id":4196,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4195\/revisions\/4196"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}