{"id":537,"date":"2023-03-23T21:19:42","date_gmt":"2023-03-23T13:19:42","guid":{"rendered":""},"modified":"2023-03-23T21:19:42","modified_gmt":"2023-03-23T13:19:42","slug":"Spring AOP","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/537.html","title":{"rendered":"Spring AOP"},"content":{"rendered":"
\n
\u4e3a\u4ec0\u4e48\u4f7f\u7528AOP\uff1f <\/p>\n
\r\nclass <\/span>A{\r\npublic void <\/span>m1(){...}\r\npublic void <\/span>m2(){...}\r\npublic void <\/span>m3(){...}\r\npublic void <\/span>m4(){...}\r\npublic void <\/span>m5(){...}\r\npublic void <\/span>n1(){...}\r\npublic void <\/span>n2(){...}\r\npublic void <\/span>p1(){...}\r\npublic void <\/span>p2(){...}\r\npublic void <\/span>p3(){...}\r\n}\r\n<\/pre>\n<\/code>\n <\/div>\n
\n \u4ecem\u5f00\u59cb\u67095\u79cd\u65b9\u6cd5\uff0c\u4ecen\u5f00\u59cb\u67092\u79cd\u65b9\u6cd5\uff0c\u4ecep\u5f00\u59cb\u67093\u79cd\u65b9\u6cd5\u3002\n <\/div>\n\n \u4e86\u89e3\u60c5\u51b5<\/b>\u6211\u5fc5\u987b\u7ef4\u62a4\u65e5\u5fd7\u5e76\u53d1\u9001\n <\/div>\n\n \u6ca1\u6709AOP\u7684\u95ee\u9898<\/b>\u6211\u4eec\u53ef\u4ee5\u4ecem\u5f00\u5934\u7684\u65b9\u6cd5\u4e2d\u8c03\u7528\u65b9\u6cd5(\u7ef4\u62a4\u65e5\u5fd7\u5e76\u53d1\u9001\u901a\u77e5)\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u6240\u67095\u79cd\u65b9\u6cd5\u7f16\u5199\u4ee3\u7801\u3002\n <\/div>\n\n \u4f46\u662f\uff0c\u5982\u679c\u5ba2\u6237\u4ee5\u540e\u8bf4\uff0c\u6211\u4e0d\u5fc5\u53d1\u9001\u901a\u77e5\uff0c\u5219\u9700\u8981\u66f4\u6539\u6240\u6709\u65b9\u6cd5\u3002\u8fd9\u4f1a\u5bfc\u81f4\u7ef4\u62a4\u95ee\u9898\u3002\n <\/div>\n\n AOP\u89e3\u51b3\u65b9\u6848<\/b>\u6211\u4eec\u4e0d\u5fc5\u4ece\u65b9\u6cd5\u4e2d\u8c03\u7528\u65b9\u6cd5\u3002\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7c7b\u7684\u65b9\u6cd5\u4e2d\u5b9a\u4e49\u5176\u4ed6\u5173\u6ce8\u70b9\uff0c\u4f8b\u5982\u7ef4\u62a4\u65e5\u5fd7\uff0c\u53d1\u9001\u901a\u77e5\u7b49\u3002\u5b83\u7684\u6761\u76ee\u5728xml\u6587\u4ef6\u4e2d\u7ed9\u51fa\u3002\n <\/div>\n\n \u5c06\u6765\uff0c\u5982\u679c\u5ba2\u6237\u8bf4\u8981\u5220\u9664\u901a\u77e5\u7a0b\u5e8f\u529f\u80fd\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5728xml\u6587\u4ef6\u4e2d\u8fdb\u884c\u66f4\u6539\u3002\u56e0\u6b64\uff0c\u5728AOP\u4e2d\u7ef4\u62a4\u5f88\u5bb9\u6613\u3002\n <\/div>\n
\n\u5728\u54ea\u91cc\u4f7f\u7528AOP\uff1f <\/h2>\n\n \u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u4e3b\u8981\u4f7f\u7528AOP:\n <\/div>\n \u63d0\u4f9b\u58f0\u660e\u5f0f\u4f01\u4e1a\u670d\u52a1\uff0c\u4f8b\u5982\u58f0\u660e\u5f0f\u4e8b\u52a1\u7ba1\u7406\u3002<\/span>
\n \u5b83\u5141\u8bb8\u7528\u6237\u5b9e\u73b0\u81ea\u5b9a\u4e49aspects\u3002<\/span> <\/p>\n
\n AOP\u6982\u5ff5\u548c\u672f\u8bed<\/h2>\n\n AOP\u6982\u5ff5\u548c\u672f\u8bed\u5982\u4e0b:\n <\/div>\n Join point<\/span>
\n Advice<\/span>
\n Pointcut<\/span>
\n Introduction<\/span>
\n Target Object<\/span>
\n Aspect<\/span>
\n Interceptor<\/span>
\n AOP Proxy<\/span>
\n Weaving<\/span> <\/p>\n
\nJoin point<\/h3>\n\n Join point\u662f\u7a0b\u5e8f\u4e2d\u7684\u4efb\u4f55\u70b9\uff0c\u4f8b\u5982\u65b9\u6cd5\u6267\u884c\uff0c\u5f02\u5e38\u5904\u7406\uff0c\u5b57\u6bb5\u8bbf\u95ee\u7b49\u3002Spring\u4ec5\u652f\u6301\u65b9\u6cd5\u6267\u884cJoin point\u3002\n <\/div>\n
\nAdvice <\/h3>\n\n Advice\u8868\u793a\u65b9\u9762\u5728\u7279\u5b9a\u7684Join point\u5904\u91c7\u53d6\u7684\u64cd\u4f5c\u3002\u6709\u4e0d\u540c\u7c7b\u578b\u7684Advice:\n <\/div>\n Before Advice: <\/b>\u5b83\u5728Join point\u4e4b\u524d\u6267\u884c\u3002<\/span>
\n After Returning Advice: <\/b>\u5728\u8054\u5408\u70b9\u6b63\u5e38\u5b8c\u6210\u540e\u6267\u884c\u3002<\/span>
\n After Throwing Advice: <\/b>\u5982\u679c\u65b9\u6cd5\u56e0\u5f15\u53d1\u5f02\u5e38\u800c\u9000\u51fa\uff0c\u5219\u6267\u884c\u3002<\/span>
\n After (finally) Advice: <\/b>\u65e0\u8bbaJoin point\u9000\u51fa\u662f\u6b63\u5e38\u8fd4\u56de\u8fd8\u662f\u5f02\u5e38\u8fd4\u56de\uff0c\u5b83\u90fd\u4f1a\u5728Join point\u4e4b\u540e\u6267\u884c\u3002<\/span>
\n Around Advice: <\/b>\u5b83\u5728Join point\u4e4b\u524d\u548c\u4e4b\u540e\u6267\u884c\u3002<\/span> <\/p>\n
\nPointcut<\/h3>\n\n \u5b83\u662fAOP\u7684\u4e00\u79cd\u8868\u8fbe\u8bed\u8a00\uff0c\u5b83\u4e0eJoin point\u76f8\u5339\u914d\u3002\n <\/div>\n
\nIntroduction<\/h3>\n\n \u8fd9\u610f\u5473\u7740\u5f15\u5165\u7c7b\u578b\u7684\u5176\u4ed6\u65b9\u6cd5\u548c\u5b57\u6bb5\u3002\u5b83\u5141\u8bb8\u60a8\u5411\u4efb\u4f55\u5efa\u8bae\u5bf9\u8c61\u5f15\u5165\u65b0\u7684\u754c\u9762\u3002\n <\/div>\n
\nTarget Object<\/h3>\n\n \u8fd9\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u65b9\u9762\u5efa\u8bae\u7684\u5bf9\u8c61\u3002\u5728Spring\uff0c\u5b83\u4e5f\u88ab\u79f0\u4e3a\u4ee3\u7406\u5bf9\u8c61\uff0c\u56e0\u4e3aSpring AOP\u662f\u4f7f\u7528\u8fd0\u884c\u65f6\u4ee3\u7406\u5b9e\u73b0\u7684\u3002\n <\/div>\n
\nAspect<\/h3>\n\n \u8fd9\u662f\u4e00\u4e2a\u5305\u542b\u5efa\u8bae\uff0cJoin point\u7b49\u7684\u7c7b\u3002\n <\/div>\n
\nInterceptor<\/h3>\n\n \u8fd9\u662f\u4e00\u4e2a\u4ec5\u5305\u542b\u4e00\u4e2a\u5efa\u8bae\u7684\u65b9\u9762\u3002\n <\/div>\n
\nAOP Proxy<\/h3>\n\n \u5b83\u7528\u4e8e\u5b9e\u73b0\u7531AOP\u6846\u67b6\u521b\u5efa\u7684\u65b9\u9762\u5408\u540c\u3002\u5728Spring\u6846\u67b6\u4e2d\u5b83\u5c06\u662fJDK\u52a8\u6001\u4ee3\u7406\u6216CGLIB\u4ee3\u7406\u3002\n <\/div>\n
\nWeaving<\/h3>\n\n \u8fd9\u662f\u5c06\u65b9\u9762\u4e0e\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u7c7b\u578b\u6216\u5bf9\u8c61\u94fe\u63a5\u5728\u4e00\u8d77\u4ee5\u521b\u5efa\u5efa\u8bae\u5bf9\u8c61\u7684\u8fc7\u7a0b\u3002\u7f16\u7ec7\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\uff0c\u52a0\u8f7d\u65f6\u6216\u8fd0\u884c\u65f6\u5b8c\u6210\u3002 Spring AOP\u5728\u8fd0\u884c\u65f6\u6267\u884c\u7f16\u7ec7\u3002\n <\/div>\n
\n AOP\u5b9e\u73b0<\/h3>\n\n AOP\u5b9e\u73b0\u7531\u4ee5\u4e0b\u63d0\u4f9b:\n <\/div>\n AspectJ <\/span>
\n SpringAOP <\/span>
\n JBoss AOP <\/span> <\/p>\n
\n Spring AOP <\/h3>\n\n Spring AOP\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e09\u79cd\u65b9\u5f0f\u4f7f\u7528\u3002\u4f46\u662f\u5e7f\u6cdb\u4f7f\u7528\u7684\u65b9\u6cd5\u662fSpring AspectJ\u6ce8\u91ca\u6837\u5f0f\u3002\u4e0b\u9762\u7ed9\u51fa\u4e86\u4f7f\u7528Spring AOP\u76843\u79cd\u65b9\u6cd5:\n <\/div>\n \u91c7\u7528Spring1.2\u65e7\u6837\u5f0f(\u57fa\u4e8edtd)(\u5728Spring3\u4e2d\u4e5f\u53d7\u652f\u6301) <\/span>
\n \u901a\u8fc7AspectJ\u6ce8\u91ca\u6837\u5f0f <\/span>
\n \u901a\u8fc7Spring XML\u914d\u7f6e\u6837\u5f0f(\u57fa\u4e8e\u6a21\u5f0f) <\/span> <\/p>\n
\n\n Spring AOP\u793a\u4f8b
\n Spring AOP AspectJ\u6ce8\u89e3\u793a\u4f8b
\n Spring AOP AspectJ Xml\u914d\u7f6e\u793a\u4f8b\n <\/div>\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Spring AOPzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-537","post","type-post","status-publish","format-standard","hentry","category-bc_spring_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/537"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=537"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/537\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}