{"id":16369,"date":"2024-09-12T20:53:26","date_gmt":"2024-09-12T12:53:26","guid":{"rendered":"https:\/\/92it.top\/?p=16369"},"modified":"2024-09-12T20:53:26","modified_gmt":"2024-09-12T12:53:26","slug":"%e8%b0%88%e8%b0%88%e4%bd%a0%e5%af%b9-ioc-%e5%92%8c-aop-%e7%9a%84%e7%90%86%e8%a7%a3%ef%bc%81","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=16369","title":{"rendered":"\u8c08\u8c08\u4f60\u5bf9 IoC \u548c AOP \u7684\u7406\u89e3\uff01"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzkzMjczMTIzOA==&amp;mid=2247483914&amp;idx=1&amp;sn=1da017e7c89d9638c0d62e35139552b1&amp;chksm=c35d1f62350a7017b7ecb73806d3409faf3da92b1c6759cdae2729a12181c9da92ea8fda8f38&amp;mpshare=1&amp;scene=1&amp;srcid=0912L1IhS6oCYnjcDM0GHAS5&amp;sharer_shareinfo=3015974a725dc3f2b9e9eea120af8af3&amp;sharer_shareinfo_first=0e3a0fadec392cc8cd0579f32b88f754&amp;exportkey=n_ChQIAhIQz6pqTCWn9EmnYf%2FinYtaqxL0AQIE97dBBAEAAAAAAOcvMVv%2FXHUAAAAOpnltbLcz9gKNyK89dVj03HljLQBRT6QXhVoG4o1RPIQs3ZHG4DhxosHec%2FD2VJvz6HZGBXM5EA9HkGnz4XLBhe6uaOXgGvEA7eBGWYeQNN9CAsRs1F%2B9Qj5iHneTXdw8HKF%2Bgh5DlXvWdkambDHR1DKj7bm0A7QQ%2FZN36SBkgKaOhKah2BcBQQ8GemR0%2Fhcs4mbXQbI6%2FVP74EXtZIWmTBdeOcoR2xs5wGtSTZFpz36%2F0gwOTyzydVwTOpqZ7V4%2FaEo%2BCMVVymwwkwXi1H7xeLhQGyNwvvSChxiQkck%3D&amp;acctmode=0&amp;pass_ticket=lI5XCmR81WaQ%2Ba5P8rysDqMF%2FqfTVf4616%2FhFIIankk0O2JeDwFAFklpdEZim0X9&amp;wx_header=0#rd\">\u9762\u8bd5\u5b98\uff1a\u8c08\u8c08\u4f60\u5bf9 IoC \u548c AOP \u7684\u7406\u89e3\uff01<\/a><\/p>\n\n\n\n<p>\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u4ece\u4e0b\u9762\u4ece\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u5c55\u5f00\u5bf9 IoC &amp; AOP \u7684\u89e3\u91ca\uff1a<\/p>\n\n\n\n<ul>\n<li>\u4ec0\u4e48\u662f IoC\uff1f<\/li>\n\n\n\n<li>IoC \u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1f<\/li>\n\n\n\n<li>IoC \u548c DI \u7684\u533a\u522b\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f AOP\uff1f<\/li>\n\n\n\n<li>AOP \u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1f<\/li>\n\n\n\n<li>AOP \u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/li>\n\n\n\n<li>AOP \u4e3a\u4ec0\u4e48\u53eb\u505a\u5207\u9762\u7f16\u7a0b\uff1f<\/li>\n\n\n\n<li>AOP \u5b9e\u73b0\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f<\/li>\n<\/ul>\n\n\n\n<p>\u9996\u5148\u58f0\u660e\uff1aIoC &amp; AOP \u4e0d\u662f Spring \u63d0\u51fa\u6765\u7684\uff0c\u5b83\u4eec\u5728 Spring \u4e4b\u524d\u5176\u5b9e\u5df2\u7ecf\u5b58\u5728\u4e86\uff0c\u53ea\u4e0d\u8fc7\u5f53\u65f6\u66f4\u52a0\u504f\u5411\u4e8e\u7406\u8bba\u3002Spring \u5728\u6280\u672f\u5c42\u6b21\u5c06\u8fd9\u4e24\u4e2a\u601d\u60f3\u8fdb\u884c\u4e86\u5f88\u597d\u7684\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p><strong><strong>\u4ec0\u4e48\u662f IoC?<\/strong><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>IoC \uff08Inversion of Control \uff09\u5373\u63a7\u5236\u53cd\u8f6c\/\u53cd\u8f6c\u63a7\u5236\u3002\u5b83\u662f\u4e00\u79cd\u601d\u60f3\u4e0d\u662f\u4e00\u4e2a\u6280\u672f\u5b9e\u73b0\u3002\u63cf\u8ff0\u7684\u662f\uff1aJava \u5f00\u53d1\u9886\u57df\u5bf9\u8c61\u7684\u521b\u5efa\u4ee5\u53ca\u7ba1\u7406\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a\u73b0\u6709\u7c7b A \u4f9d\u8d56\u4e8e\u7c7b B<\/p>\n\n\n\n<ul>\n<li><strong>\u4f20\u7edf\u7684\u5f00\u53d1\u65b9\u5f0f<\/strong> \uff1a\u5f80\u5f80\u662f\u5728\u7c7b A \u4e2d\u624b\u52a8\u901a\u8fc7 new \u5173\u952e\u5b57\u6765 new \u4e00\u4e2a B \u7684\u5bf9\u8c61\u51fa\u6765<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 IoC \u601d\u60f3\u7684\u5f00\u53d1\u65b9\u5f0f<\/strong> \uff1a\u4e0d\u901a\u8fc7 new \u5173\u952e\u5b57\u6765\u521b\u5efa\u5bf9\u8c61\uff0c\u800c\u662f\u901a\u8fc7 IoC \u5bb9\u5668(Spring \u6846\u67b6) \u6765\u5e2e\u52a9\u6211\u4eec\u5b9e\u4f8b\u5316\u5bf9\u8c61\u3002\u6211\u4eec\u9700\u8981\u54ea\u4e2a\u5bf9\u8c61\uff0c\u76f4\u63a5\u4ece IoC \u5bb9\u5668\u91cc\u9762\u53bb\u53d6\u5373\u53ef\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4ece\u4ee5\u4e0a\u4e24\u79cd\u5f00\u53d1\u65b9\u5f0f\u7684\u5bf9\u6bd4\u6765\u770b\uff1a\u6211\u4eec \u201c\u4e27\u5931\u4e86\u4e00\u4e2a\u6743\u529b\u201d (\u521b\u5efa\u3001\u7ba1\u7406\u5bf9\u8c61\u7684\u6743\u529b)\uff0c\u4ece\u800c\u4e5f\u5f97\u5230\u4e86\u4e00\u4e2a\u597d\u5904\uff08\u4e0d\u7528\u518d\u8003\u8651\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u7ba1\u7406\u7b49\u4e00\u7cfb\u5217\u7684\u4e8b\u60c5\uff09<\/p>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u53eb\u63a7\u5236\u53cd\u8f6c?<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u63a7\u5236<\/strong> \uff1a\u6307\u7684\u662f\u5bf9\u8c61\u521b\u5efa\uff08\u5b9e\u4f8b\u5316\u3001\u7ba1\u7406\uff09\u7684\u6743\u529b<\/li>\n\n\n\n<li><strong>\u53cd\u8f6c<\/strong> \uff1a\u63a7\u5236\u6743\u4ea4\u7ed9\u5916\u90e8\u73af\u5883\uff08IoC \u5bb9\u5668\uff09<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"415\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-1024x415.png\" alt=\"\" class=\"wp-image-16370\" style=\"width:538px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-1024x415.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-300x122.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-768x311.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-1536x623.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-2048x830.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-830x337.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-230x93.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-350x142.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-126-480x195.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>IoC \u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898?<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>IoC \u7684\u601d\u60f3\u5c31\u662f\u4e24\u65b9\u4e4b\u95f4\u4e0d\u4e92\u76f8\u4f9d\u8d56\uff0c\u7531\u7b2c\u4e09\u65b9\u5bb9\u5668\u6765\u7ba1\u7406\u76f8\u5173\u8d44\u6e90\u3002\u8fd9\u6837\u6709\u4ec0\u4e48\u597d\u5904\u5462\uff1f<\/p>\n\n\n\n<ol>\n<li>\u5bf9\u8c61\u4e4b\u95f4\u7684\u8026\u5408\u5ea6\u6216\u8005\u8bf4\u4f9d\u8d56\u7a0b\u5ea6\u964d\u4f4e\uff1b<\/li>\n\n\n\n<li>\u8d44\u6e90\u53d8\u7684\u5bb9\u6613\u7ba1\u7406\uff1b\u6bd4\u5982\u4f60\u7528 Spring \u5bb9\u5668\u63d0\u4f9b\u7684\u8bdd\u5f88\u5bb9\u6613\u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u5355\u4f8b\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u4f8b\u5982\uff1a\u73b0\u6709\u4e00\u4e2a\u9488\u5bf9 User \u7684\u64cd\u4f5c\uff0c\u5229\u7528 Service \u548c Dao \u4e24\u5c42\u7ed3\u6784\u8fdb\u884c\u5f00\u53d1<\/p>\n\n\n\n<p>\u5728\u6ca1\u6709\u4f7f\u7528 IoC \u601d\u60f3\u7684\u60c5\u51b5\u4e0b\uff0cService \u5c42\u60f3\u8981\u4f7f\u7528 Dao \u5c42\u7684\u5177\u4f53\u5b9e\u73b0\u7684\u8bdd\uff0c\u9700\u8981\u901a\u8fc7 new \u5173\u952e\u5b57\u5728<code>UserServiceImpl<\/code> \u4e2d\u624b\u52a8 new \u51fa <code>IUserDao<\/code> \u7684\u5177\u4f53\u5b9e\u73b0\u7c7b <code>UserDaoImpl<\/code>\uff08\u4e0d\u80fd\u76f4\u63a5 new \u63a5\u53e3\u7c7b\uff09\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"440\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-1024x440.png\" alt=\"\" class=\"wp-image-16371\" style=\"width:546px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-1024x440.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-300x129.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-768x330.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-1536x660.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-830x357.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-230x99.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-350x151.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127-480x206.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-127.png 1586w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5f88\u5b8c\u7f8e\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4e5f\u662f\u53ef\u4ee5\u5b9e\u73b0\u7684\uff0c\u4f46\u662f\u6211\u4eec\u60f3\u8c61\u4e00\u4e0b\u5982\u4e0b\u573a\u666f\uff1a<\/p>\n\n\n\n<p>\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7a81\u7136\u63a5\u5230\u4e00\u4e2a\u65b0\u7684\u9700\u6c42\uff0c\u9488\u5bf9<code>IUserDao<\/code> \u63a5\u53e3\u5f00\u53d1\u51fa\u53e6\u4e00\u4e2a\u5177\u4f53\u5b9e\u73b0\u7c7b\u3002\u56e0\u4e3a Server \u5c42\u4f9d\u8d56\u4e86<code>IUserDao<\/code>\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4fee\u6539<code>UserServiceImpl<\/code>\u4e2d new \u7684\u5bf9\u8c61\u3002\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u7c7b\u5f15\u7528\u4e86<code>IUserDao<\/code>\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u53ef\u80fd\u89c9\u5f97\u8fd8\u597d\uff0c\u4fee\u6539\u8d77\u6765\u4e5f\u4e0d\u662f\u5f88\u8d39\u529b\u6c14\uff0c\u4f46\u662f\u5982\u679c\u6709\u8bb8\u8bb8\u591a\u591a\u7684\u5730\u65b9\u90fd\u5f15\u7528\u4e86<code>IUserDao<\/code>\u7684\u5177\u4f53\u5b9e\u73b0\u7684\u8bdd\uff0c\u4e00\u65e6\u9700\u8981\u66f4\u6362<code>IUserDao<\/code> \u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u90a3\u4fee\u6539\u8d77\u6765\u5c06\u4f1a\u975e\u5e38\u7684\u5934\u75bc\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"487\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-1024x487.png\" alt=\"\" class=\"wp-image-16372\" style=\"width:538px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-1024x487.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-300x143.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-768x365.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-1536x731.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-830x395.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-230x109.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-350x166.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128-480x228.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-128.png 1564w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u4f7f\u7528 IoC \u7684\u601d\u60f3\uff0c\u6211\u4eec\u5c06\u5bf9\u8c61\u7684\u63a7\u5236\u6743\uff08\u521b\u5efa\u3001\u7ba1\u7406\uff09\u4ea4\u7531 IoC \u5bb9\u5668\u53bb\u7ba1\u7406\uff0c\u6211\u4eec\u5728\u4f7f\u7528\u7684\u65f6\u5019\u76f4\u63a5\u5411 IoC \u5bb9\u5668 \u201c\u8981\u201d \u5c31\u53ef\u4ee5\u4e86<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"486\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-1024x486.png\" alt=\"\" class=\"wp-image-16373\" style=\"width:522px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-1024x486.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-300x142.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-768x365.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-1536x729.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-830x394.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-230x109.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-350x166.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129-480x228.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-129.png 1580w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>IoC \u548c DI \u6709\u533a\u522b\u5417\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>IoC\uff08Inverse of Control:\u63a7\u5236\u53cd\u8f6c\uff09\u662f\u4e00\u79cd\u8bbe\u8ba1\u601d\u60f3\u6216\u8005\u8bf4\u662f\u67d0\u79cd\u6a21\u5f0f\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u601d\u60f3\u5c31\u662f <strong>\u5c06\u539f\u672c\u5728\u7a0b\u5e8f\u4e2d\u624b\u52a8\u521b\u5efa\u5bf9\u8c61\u7684\u63a7\u5236\u6743\u4ea4\u7ed9\u7b2c\u4e09\u65b9\u6bd4\u5982 IoC \u5bb9\u5668\u3002<\/strong> \u5bf9\u4e8e\u6211\u4eec\u5e38\u7528\u7684 Spring \u6846\u67b6\u6765\u8bf4\uff0c IoC \u5bb9\u5668\u5b9e\u9645\u4e0a\u5c31\u662f\u4e2a Map\uff08key\uff0cvalue\uff09,Map \u4e2d\u5b58\u653e\u7684\u662f\u5404\u79cd\u5bf9\u8c61\u3002\u4e0d\u8fc7\uff0cIoC \u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e5f\u6709\u5e94\u7528\uff0c\u5e76\u975e Spring \u7279\u6709\u3002<\/p>\n\n\n\n<p>IoC \u6700\u5e38\u89c1\u4ee5\u53ca\u6700\u5408\u7406\u7684\u5b9e\u73b0\u65b9\u5f0f\u53eb\u505a\u4f9d\u8d56\u6ce8\u5165\uff08Dependency Injection\uff0c\u7b80\u79f0 DI\uff09\u3002<\/p>\n\n\n\n<p>\u8001\u9a6c\uff08Martin Fowler\uff09\u5728\u4e00\u7bc7\u6587\u7ae0\u4e2d\u63d0\u5230\u5c06 IoC \u6539\u540d\u4e3a DI\uff0c\u539f\u6587\u5982\u4e0b\uff0c\u539f\u6587\u5730\u5740\uff1ahttps:\/\/martinfowler.com\/articles\/injection.html \u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"566\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-1024x566.png\" alt=\"\" class=\"wp-image-16374\" style=\"width:506px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-1024x566.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-300x166.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-768x424.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-1536x848.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-830x458.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-230x127.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-350x193.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130-480x265.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-130.png 1546w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u8001\u9a6c\u7684\u5927\u6982\u610f\u601d\u662f IoC \u592a\u666e\u904d\u5e76\u4e14\u4e0d\u8868\u610f\uff0c\u5f88\u591a\u4eba\u4f1a\u56e0\u6b64\u800c\u8ff7\u60d1\uff0c\u6240\u4ee5\uff0c\u4f7f\u7528 DI \u6765\u7cbe\u786e\u6307\u540d\u8fd9\u4e2a\u6a21\u5f0f\u6bd4\u8f83\u597d\u3002<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662f AOP\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>AOP\uff08Aspect Oriented Programming\uff09\u5373\u9762\u5411\u5207\u9762\u7f16\u7a0b\uff0cAOP \u662f OOP\uff08\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff09\u7684\u4e00\u79cd\u5ef6\u7eed\uff0c\u4e8c\u8005\u4e92\u8865\uff0c\u5e76\u4e0d\u5bf9\u7acb\u3002<\/p>\n\n\n\n<p>AOP \u7684\u76ee\u7684\u662f\u5c06\u6a2a\u5207\u5173\u6ce8\u70b9\uff08\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u4e8b\u52a1\u7ba1\u7406\u3001\u6743\u9650\u63a7\u5236\u3001\u63a5\u53e3\u9650\u6d41\u3001\u63a5\u53e3\u5e42\u7b49\u7b49\uff09\u4ece\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u4e2d\u5206\u79bb\u51fa\u6765\uff0c\u901a\u8fc7\u52a8\u6001\u4ee3\u7406\u3001\u5b57\u8282\u7801\u64cd\u4f5c\u7b49\u6280\u672f\uff0c\u5b9e\u73b0\u4ee3\u7801\u7684\u590d\u7528\u548c\u89e3\u8026\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002OOP \u7684\u76ee\u7684\u662f\u5c06\u4e1a\u52a1\u903b\u8f91\u6309\u7167\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u884c\u4e3a\u8fdb\u884c\u5c01\u88c5\uff0c\u901a\u8fc7\u7c7b\u3001\u5bf9\u8c61\u3001\u7ee7\u627f\u3001\u591a\u6001\u7b49\u6982\u5ff5\uff0c\u5b9e\u73b0\u4ee3\u7801\u7684\u6a21\u5757\u5316\u548c\u5c42\u6b21\u5316\uff08\u4e5f\u80fd\u5b9e\u73b0\u4ee3\u7801\u7684\u590d\u7528\uff09\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n\n\n\n<p><strong>AOP \u4e3a\u4ec0\u4e48\u53eb\u9762\u5411\u5207\u9762\u7f16\u7a0b\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>AOP \u4e4b\u6240\u4ee5\u53eb\u9762\u5411\u5207\u9762\u7f16\u7a0b\uff0c\u662f\u56e0\u4e3a\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u5c31\u662f\u5c06\u6a2a\u5207\u5173\u6ce8\u70b9\u4ece\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u4e2d\u5206\u79bb\u51fa\u6765\uff0c\u5f62\u6210\u4e00\u4e2a\u4e2a\u7684<strong>\u5207\u9762\uff08Aspect\uff09<\/strong>\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u987a\u5e26\u603b\u7ed3\u4e00\u4e0b AOP \u5173\u952e\u672f\u8bed\uff08\u4e0d\u7406\u89e3\u4e5f\u6ca1\u5173\u7cfb\uff0c\u53ef\u4ee5\u7ee7\u7eed\u5f80\u4e0b\u770b\uff09\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>\u6a2a\u5207\u5173\u6ce8\u70b9\uff08cross-cutting concerns\uff09<\/strong> \uff1a\u591a\u4e2a\u7c7b\u6216\u5bf9\u8c61\u4e2d\u7684\u516c\u5171\u884c\u4e3a\uff08\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u4e8b\u52a1\u7ba1\u7406\u3001\u6743\u9650\u63a7\u5236\u3001\u63a5\u53e3\u9650\u6d41\u3001\u63a5\u53e3\u5e42\u7b49\u7b49\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5207\u9762\uff08Aspect\uff09<\/strong>\uff1a\u5bf9\u6a2a\u5207\u5173\u6ce8\u70b9\u8fdb\u884c\u5c01\u88c5\u7684\u7c7b\uff0c\u4e00\u4e2a\u5207\u9762\u662f\u4e00\u4e2a\u7c7b\u3002\u5207\u9762\u53ef\u4ee5\u5b9a\u4e49\u591a\u4e2a\u901a\u77e5\uff0c\u7528\u6765\u5b9e\u73b0\u5177\u4f53\u7684\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u8fde\u63a5\u70b9\uff08JoinPoint\uff09<\/strong>\uff1a\u8fde\u63a5\u70b9\u662f\u65b9\u6cd5\u8c03\u7528\u6216\u8005\u65b9\u6cd5\u6267\u884c\u65f6\u7684\u67d0\u4e2a\u7279\u5b9a\u65f6\u523b\uff08\u5982\u65b9\u6cd5\u8c03\u7528\u3001\u5f02\u5e38\u629b\u51fa\u7b49\uff09\u3002<\/li>\n\n\n\n<li><strong>\u901a\u77e5\uff08Advice\uff09<\/strong>\uff1a\u901a\u77e5\u5c31\u662f\u5207\u9762\u5728\u67d0\u4e2a\u8fde\u63a5\u70b9\u8981\u6267\u884c\u7684\u64cd\u4f5c\u3002\u901a\u77e5\u6709\u4e94\u79cd\u7c7b\u578b\uff0c\u5206\u522b\u662f\u524d\u7f6e\u901a\u77e5\uff08Before\uff09\u3001\u540e\u7f6e\u901a\u77e5\uff08After\uff09\u3001\u8fd4\u56de\u901a\u77e5\uff08AfterReturning\uff09\u3001\u5f02\u5e38\u901a\u77e5\uff08AfterThrowing\uff09\u548c\u73af\u7ed5\u901a\u77e5\uff08Around\uff09\u3002\u524d\u56db\u79cd\u901a\u77e5\u90fd\u662f\u5728\u76ee\u6807\u65b9\u6cd5\u7684\u524d\u540e\u6267\u884c\uff0c\u800c\u73af\u7ed5\u901a\u77e5\u53ef\u4ee5\u63a7\u5236\u76ee\u6807\u65b9\u6cd5\u7684\u6267\u884c\u8fc7\u7a0b\u3002<\/li>\n\n\n\n<li><strong>\u5207\u70b9\uff08Pointcut\uff09<\/strong>\uff1a\u4e00\u4e2a\u5207\u70b9\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u7528\u6765\u5339\u914d\u54ea\u4e9b\u8fde\u63a5\u70b9\u9700\u8981\u88ab\u5207\u9762\u6240\u589e\u5f3a\u3002\u5207\u70b9\u53ef\u4ee5\u901a\u8fc7\u6ce8\u89e3\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u903b\u8f91\u8fd0\u7b97\u7b49\u65b9\u5f0f\u6765\u5b9a\u4e49\u3002\u6bd4\u5982 <code>execution(* com.xyz.service..*(..))<\/code>\u5339\u914d <code>com.xyz.service<\/code> \u5305\u53ca\u5176\u5b50\u5305\u4e0b\u7684\u7c7b\u6216\u63a5\u53e3\u3002<\/li>\n\n\n\n<li><strong>\u7ec7\u5165\uff08Weaving\uff09<\/strong>\uff1a\u7ec7\u5165\u662f\u5c06\u5207\u9762\u548c\u76ee\u6807\u5bf9\u8c61\u8fde\u63a5\u8d77\u6765\u7684\u8fc7\u7a0b\uff0c\u4e5f\u5c31\u662f\u5c06\u901a\u77e5\u5e94\u7528\u5230\u5207\u70b9\u5339\u914d\u7684\u8fde\u63a5\u70b9\u4e0a\u3002\u5e38\u89c1\u7684\u7ec7\u5165\u65f6\u673a\u6709\u4e24\u79cd\uff0c\u5206\u522b\u662f\u7f16\u8bd1\u671f\u7ec7\u5165\uff08Compile-Time Weaving \u5982\uff1aAspectJ\uff09\u548c\u8fd0\u884c\u671f\u7ec7\u5165\uff08Runtime Weaving \u5982\uff1aAspectJ\u3001Spring AOP\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>AOP \u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>OOP \u4e0d\u80fd\u5f88\u597d\u5730\u5904\u7406\u4e00\u4e9b\u5206\u6563\u5728\u591a\u4e2a\u7c7b\u6216\u5bf9\u8c61\u4e2d\u7684\u516c\u5171\u884c\u4e3a\uff08\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u4e8b\u52a1\u7ba1\u7406\u3001\u6743\u9650\u63a7\u5236\u3001\u63a5\u53e3\u9650\u6d41\u3001\u63a5\u53e3\u5e42\u7b49\u7b49\uff09\uff0c\u8fd9\u4e9b\u884c\u4e3a\u901a\u5e38\u88ab\u79f0\u4e3a <strong>\u6a2a\u5207\u5173\u6ce8\u70b9\uff08cross-cutting concerns\uff09<\/strong> \u3002\u5982\u679c\u6211\u4eec\u5728\u6bcf\u4e2a\u7c7b\u6216\u5bf9\u8c61\u4e2d\u90fd\u91cd\u590d\u5b9e\u73b0\u8fd9\u4e9b\u884c\u4e3a\uff0c\u90a3\u4e48\u4f1a\u5bfc\u81f4\u4ee3\u7801\u7684\u5197\u4f59\u3001\u590d\u6742\u548c\u96be\u4ee5\u7ef4\u62a4\u3002<\/p>\n\n\n\n<p>AOP \u53ef\u4ee5\u5c06\u6a2a\u5207\u5173\u6ce8\u70b9\uff08\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u4e8b\u52a1\u7ba1\u7406\u3001\u6743\u9650\u63a7\u5236\u3001\u63a5\u53e3\u9650\u6d41\u3001\u63a5\u53e3\u5e42\u7b49\u7b49\uff09\u4ece <strong>\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\uff08core concerns\uff0c\u6838\u5fc3\u5173\u6ce8\u70b9\uff09<\/strong> \u4e2d\u5206\u79bb\u51fa\u6765\uff0c\u5b9e\u73b0\u5173\u6ce8\u70b9\u7684\u5206\u79bb\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"601\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-1024x601.png\" alt=\"\" class=\"wp-image-16376\" style=\"width:522px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-1024x601.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-300x176.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-768x450.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-1536x901.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-830x487.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-230x135.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-350x205.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132-480x281.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-132.png 1654w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u4ee5\u65e5\u5fd7\u8bb0\u5f55\u4e3a\u4f8b\u8fdb\u884c\u4ecb\u7ecd\uff0c\u5047\u5982\u6211\u4eec\u9700\u8981\u5bf9\u67d0\u4e9b\u65b9\u6cd5\u8fdb\u884c\u7edf\u4e00\u683c\u5f0f\u7684\u65e5\u5fd7\u8bb0\u5f55\uff0c\u6ca1\u6709\u4f7f\u7528 AOP \u6280\u672f\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u6328\u4e2a\u5199\u65e5\u5fd7\u8bb0\u5f55\u7684\u903b\u8f91\u4ee3\u7801\uff0c\u5168\u662f\u91cd\u590d\u7684\u7684\u903b\u8f91\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public CommonResponse&lt;Object> method1() {\n      \/\/ \u4e1a\u52a1\u903b\u8f91\n      xxService.method1();\n      \/\/ \u7701\u7565\u5177\u4f53\u7684\u4e1a\u52a1\u5904\u7406\u903b\u8f91\n      \/\/ \u65e5\u5fd7\u8bb0\u5f55\n      ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();\n      HttpServletRequest request = attributes.getRequest();\n      \/\/ \u7701\u7565\u8bb0\u5f55\u65e5\u5fd7\u7684\u5177\u4f53\u903b\u8f91 \u5982\uff1a\u83b7\u53d6\u5404\u79cd\u4fe1\u606f\uff0c\u5199\u5165\u6570\u636e\u5e93\u7b49\u64cd\u4f5c...\n      return CommonResponse.success();\n}\n\npublic CommonResponse&lt;Object> method2() {\n      \/\/ \u4e1a\u52a1\u903b\u8f91\n      xxService.method2();\n      \/\/ \u7701\u7565\u5177\u4f53\u7684\u4e1a\u52a1\u5904\u7406\u903b\u8f91\n      \/\/ \u65e5\u5fd7\u8bb0\u5f55\n      ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();\n      HttpServletRequest request = attributes.getRequest();\n      \/\/ \u7701\u7565\u8bb0\u5f55\u65e5\u5fd7\u7684\u5177\u4f53\u903b\u8f91 \u5982\uff1a\u83b7\u53d6\u5404\u79cd\u4fe1\u606f\uff0c\u5199\u5165\u6570\u636e\u5e93\u7b49\u64cd\u4f5c...\n      return CommonResponse.success();\n}\n\n\/\/ ...<\/pre>\n\n\n\n<p>\u4f7f\u7528 AOP \u6280\u672f\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u65e5\u5fd7\u8bb0\u5f55\u7684\u903b\u8f91\u5c01\u88c5\u6210\u4e00\u4e2a\u5207\u9762\uff0c\u7136\u540e\u901a\u8fc7\u5207\u5165\u70b9\u548c\u901a\u77e5\u6765\u6307\u5b9a\u5728\u54ea\u4e9b\u65b9\u6cd5\u9700\u8981\u6267\u884c\u65e5\u5fd7\u8bb0\u5f55\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u65e5\u5fd7\u6ce8\u89e3\n@Target({ElementType.PARAMETER,ElementType.METHOD})\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\npublic @interface Log {\n\n    \/**\n     * \u63cf\u8ff0\n     *\/\n    String description() default \"\";\n\n    \/**\n     * \u65b9\u6cd5\u7c7b\u578b INSERT DELETE UPDATE OTHER\n     *\/\n    MethodType methodType() default MethodType.OTHER;\n}\n\n\/\/ \u65e5\u5fd7\u5207\u9762\n@Component\n@Aspect\npublic class LogAspect {\n  \/\/ \u5207\u5165\u70b9\uff0c\u6240\u6709\u88ab Log \u6ce8\u89e3\u6807\u6ce8\u7684\u65b9\u6cd5\n  @Pointcut(\"@annotation(cn.javaguide.annotation.Log)\")\n  public void webLog() {\n  }\n\n   \/**\n   * \u73af\u7ed5\u901a\u77e5\n   *\/\n  @Around(\"webLog()\")\n  public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {\n    \/\/ \u7701\u7565\u5177\u4f53\u7684\u5904\u7406\u903b\u8f91\n  }\n\n  \/\/ \u7701\u7565\u5176\u4ed6\u4ee3\u7801\n}<\/pre>\n\n\n\n<p>\u8fd9\u6837\u7684\u8bdd\uff0c\u6211\u4eec\u4e00\u884c\u6ce8\u89e3\u5373\u53ef\u5b9e\u73b0\u65e5\u5fd7\u8bb0\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Log(description = \"method1\",methodType = MethodType.INSERT)\npublic CommonResponse&lt;Object> method1() {\n      \/\/ \u4e1a\u52a1\u903b\u8f91\n      xxService.method1();\n      \/\/ \u7701\u7565\u5177\u4f53\u7684\u4e1a\u52a1\u5904\u7406\u903b\u8f91\n      return CommonResponse.success();\n}<\/pre>\n\n\n\n<p><strong>AOP \u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li>\u65e5\u5fd7\u8bb0\u5f55\uff1a\u81ea\u5b9a\u4e49\u65e5\u5fd7\u8bb0\u5f55\u6ce8\u89e3\uff0c\u5229\u7528 AOP\uff0c\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\u65e5\u5fd7\u8bb0\u5f55\u3002<\/li>\n\n\n\n<li>\u6027\u80fd\u7edf\u8ba1\uff1a\u5229\u7528 AOP \u5728\u76ee\u6807\u65b9\u6cd5\u7684\u6267\u884c\u524d\u540e\u7edf\u8ba1\u65b9\u6cd5\u7684\u6267\u884c\u65f6\u95f4\uff0c\u65b9\u4fbf\u4f18\u5316\u548c\u5206\u6790\u3002<\/li>\n\n\n\n<li>\u4e8b\u52a1\u7ba1\u7406\uff1a<code>@Transactional<\/code> \u6ce8\u89e3\u53ef\u4ee5\u8ba9 Spring \u4e3a\u6211\u4eec\u8fdb\u884c\u4e8b\u52a1\u7ba1\u7406\u6bd4\u5982\u56de\u6eda\u5f02\u5e38\u64cd\u4f5c\uff0c\u514d\u53bb\u4e86\u91cd\u590d\u7684\u4e8b\u52a1\u7ba1\u7406\u903b\u8f91\u3002<code>@Transactional<\/code>\u6ce8\u89e3\u5c31\u662f\u57fa\u4e8e AOP \u5b9e\u73b0\u7684\u3002<\/li>\n\n\n\n<li>\u6743\u9650\u63a7\u5236\uff1a\u5229\u7528 AOP \u5728\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u524d\u5224\u65ad\u7528\u6237\u662f\u5426\u5177\u5907\u6240\u9700\u8981\u7684\u6743\u9650\uff0c\u5982\u679c\u5177\u5907\uff0c\u5c31\u6267\u884c\u76ee\u6807\u65b9\u6cd5\uff0c\u5426\u5219\u5c31\u4e0d\u6267\u884c\u3002\u4f8b\u5982\uff0cSpringSecurity \u5229\u7528<code>@PreAuthorize<\/code> \u6ce8\u89e3\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u81ea\u5b9a\u4e49\u6743\u9650\u6821\u9a8c\u3002<\/li>\n\n\n\n<li>\u63a5\u53e3\u9650\u6d41\uff1a\u5229\u7528 AOP \u5728\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u524d\u901a\u8fc7\u5177\u4f53\u7684\u9650\u6d41\u7b97\u6cd5\u548c\u5b9e\u73b0\u5bf9\u8bf7\u6c42\u8fdb\u884c\u9650\u6d41\u5904\u7406\u3002<\/li>\n\n\n\n<li>\u7f13\u5b58\u7ba1\u7406\uff1a\u5229\u7528 AOP \u5728\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u524d\u540e\u8fdb\u884c\u7f13\u5b58\u7684\u8bfb\u53d6\u548c\u66f4\u65b0\u3002<\/li>\n\n\n\n<li>\u2026\u2026<\/li>\n<\/ul>\n\n\n\n<p><strong>AOP \u5b9e\u73b0\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>AOP \u7684\u5e38\u89c1\u5b9e\u73b0\u65b9\u5f0f\u6709\u52a8\u6001\u4ee3\u7406\u3001\u5b57\u8282\u7801\u64cd\u4f5c\u7b49\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p>Spring AOP \u5c31\u662f\u57fa\u4e8e\u52a8\u6001\u4ee3\u7406\u7684\uff0c\u5982\u679c\u8981\u4ee3\u7406\u7684\u5bf9\u8c61\uff0c\u5b9e\u73b0\u4e86\u67d0\u4e2a\u63a5\u53e3\uff0c\u90a3\u4e48 Spring AOP \u4f1a\u4f7f\u7528 <strong>JDK Proxy<\/strong>\uff0c\u53bb\u521b\u5efa\u4ee3\u7406\u5bf9\u8c61\uff0c\u800c\u5bf9\u4e8e\u6ca1\u6709\u5b9e\u73b0\u63a5\u53e3\u7684\u5bf9\u8c61\uff0c\u5c31\u65e0\u6cd5\u4f7f\u7528 JDK Proxy \u53bb\u8fdb\u884c\u4ee3\u7406\u4e86\uff0c\u8fd9\u65f6\u5019 Spring AOP \u4f1a\u4f7f\u7528 <strong>Cglib<\/strong> \u751f\u6210\u4e00\u4e2a\u88ab\u4ee3\u7406\u5bf9\u8c61\u7684\u5b50\u7c7b\u6765\u4f5c\u4e3a\u4ee3\u7406\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-1024x582.png\" alt=\"\" class=\"wp-image-16378\" style=\"width:484px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-1024x582.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-300x170.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-768x436.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-1536x873.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-830x472.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-230x131.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-350x199.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134-480x273.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/09\/\u56fe\u7247-134.png 1552w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 <strong>AspectJ<\/strong> \uff01Spring AOP \u5df2\u7ecf\u96c6\u6210\u4e86 AspectJ \uff0cAspectJ \u5e94\u8be5\u7b97\u7684\u4e0a\u662f Java \u751f\u6001\u7cfb\u7edf\u4e2d\u6700\u5b8c\u6574\u7684 AOP \u6846\u67b6\u4e86\u3002<\/p>\n\n\n\n<p><strong>Spring AOP \u5c5e\u4e8e\u8fd0\u884c\u65f6\u589e\u5f3a\uff0c\u800c AspectJ \u662f\u7f16\u8bd1\u65f6\u589e\u5f3a\u3002<\/strong> Spring AOP \u57fa\u4e8e\u4ee3\u7406(Proxying)\uff0c\u800c AspectJ \u57fa\u4e8e\u5b57\u8282\u7801\u64cd\u4f5c(Bytecode Manipulation)\u3002<\/p>\n\n\n\n<p>Spring AOP \u5df2\u7ecf\u96c6\u6210\u4e86 AspectJ \uff0cAspectJ \u5e94\u8be5\u7b97\u7684\u4e0a\u662f Java \u751f\u6001\u7cfb\u7edf\u4e2d\u6700\u5b8c\u6574\u7684 AOP \u6846\u67b6\u4e86\u3002AspectJ \u76f8\u6bd4\u4e8e Spring AOP \u529f\u80fd\u66f4\u52a0\u5f3a\u5927\uff0c\u4f46\u662f Spring AOP \u76f8\u5bf9\u6765\u8bf4\u66f4\u7b80\u5355\uff0c<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u7684\u5207\u9762\u6bd4\u8f83\u5c11\uff0c\u90a3\u4e48\u4e24\u8005\u6027\u80fd\u5dee\u5f02\u4e0d\u5927\u3002\u4f46\u662f\uff0c\u5f53\u5207\u9762\u592a\u591a\u7684\u8bdd\uff0c\u6700\u597d\u9009\u62e9 AspectJ \uff0c\u5b83\u6bd4 Spring AOP \u5feb\u5f88\u591a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1a\u9762\u8bd5\u5b98\uff1a\u8c08\u8c08\u4f60\u5bf9 IoC \u548c AOP \u7684\u7406\u89e3\uff01 \u8fd9\u7bc7\u6587\u7ae0\u4f1a\u4ece\u4e0b\u9762\u4ece\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u5c55\u5f00\u5bf9 IoC &amp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16369"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16369"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16369\/revisions"}],"predecessor-version":[{"id":16379,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16369\/revisions\/16379"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}