{"id":11598,"date":"2023-11-28T22:27:24","date_gmt":"2023-11-28T14:27:24","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=11598"},"modified":"2023-12-11T11:27:51","modified_gmt":"2023-12-11T03:27:51","slug":"spring-de-lian-jie-dian-shi-shen-me","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-de-lian-jie-dian-shi-shen-me\/","title":{"rendered":"Spring\u7684\u8fde\u63a5\u70b9\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p>\u5728\u9762\u5411\u5207\u9762\u7f16\u7a0b\uff08AOP\uff09\u4e2d\uff0c\u8fde\u63a5\u70b9\uff08Join Point\uff09\u662f\u5728\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u80fd\u591f\u63d2\u5165\u5207\u9762\u7684\u70b9\u3002\u8fde\u63a5\u70b9\u53ef\u4ee5\u662f\u65b9\u6cd5\u7684\u6267\u884c\u3001\u5f02\u5e38\u7684\u629b\u51fa\u3001\u5b57\u6bb5\u7684\u8bbf\u95ee\u7b49\u7b49\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u8fde\u63a5\u70b9\u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u80fd\u591f\u88ab\u62e6\u622a\u7684\u70b9\u3002<\/p>\n<p>\u5728Spring AOP\u4e2d\uff0c\u8fde\u63a5\u70b9\u901a\u5e38\u662f\u65b9\u6cd5\u7684\u6267\u884c\u3002Spring AOP\u4ec5\u652f\u6301\u65b9\u6cd5\u7ea7\u522b\u7684\u8fde\u63a5\u70b9\uff0c\u4e0d\u652f\u6301\u5b57\u6bb5\u7ea7\u522b\u7684\u8fde\u63a5\u70b9\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5173\u4e8e\u8fde\u63a5\u70b9\u7684\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<strong>\u65b9\u6cd5\u6267\u884c\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fde\u63a5\u70b9\u662f\u65b9\u6cd5\u7684\u6267\u884c\uff0c\u53ef\u4ee5\u5728\u65b9\u6cd5\u6267\u884c\u524d\u3001\u6267\u884c\u540e\u3001\u629b\u51fa\u5f02\u5e38\u65f6\u7b49\u65f6\u673a\u63d2\u5165\u5207\u9762\u7684\u903b\u8f91\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class MyService {\n    public void myMethod() {\n        \/\/ \u65b9\u6cd5\u4f53\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"language-java\">@Aspect\npublic class MyAspect {\n    @Before(&quot;execution(* com.example.MyService.myMethod())&quot;)\n    public void beforeMyMethod() {\n        \/\/ \u5728\u65b9\u6cd5\u6267\u884c\u524d\u6267\u884c\u7684\u903b\u8f91\n    }\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>\u5f02\u5e38\u629b\u51fa\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fde\u63a5\u70b9\u662f\u65b9\u6cd5\u629b\u51fa\u5f02\u5e38\u7684\u65f6\u5019\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class MyService {\n    public void myMethod() {\n        \/\/ \u65b9\u6cd5\u4f53\uff0c\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"language-java\">@Aspect\npublic class MyAspect {\n    @AfterThrowing(pointcut = &quot;execution(* com.example.MyService.myMethod())&quot;, throwing = &quot;ex&quot;)\n    public void afterThrowingMyMethod(Exception ex) {\n        \/\/ \u5728\u65b9\u6cd5\u629b\u51fa\u5f02\u5e38\u65f6\u6267\u884c\u7684\u903b\u8f91\n    }\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>\u65b9\u6cd5\u8c03\u7528\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fde\u63a5\u70b9\u662f\u5176\u4ed6\u65b9\u6cd5\u8c03\u7528\u7684\u65f6\u5019\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class MyService {\n    public void myMethod() {\n        anotherMethod();\n    }\n\n    public void anotherMethod() {\n        \/\/ \u65b9\u6cd5\u4f53\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"language-java\">@Aspect\npublic class MyAspect {\n    @Before(&quot;execution(* com.example.MyService.anotherMethod())&quot;)\n    public void beforeAnotherMethod() {\n        \/\/ \u5728 anotherMethod \u88ab\u8c03\u7528\u524d\u6267\u884c\u7684\u903b\u8f91\n    }\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fde\u63a5\u70b9\u7531\u5207\u70b9\uff08Pointcut\uff09\u548c\u901a\u77e5\uff08Advice\uff09\u7ec4\u6210\u3002\u5207\u70b9\u5b9a\u4e49\u4e86\u4e00\u7ec4\u8fde\u63a5\u70b9\uff0c\u800c\u901a\u77e5\u662f\u5728\u8fde\u63a5\u70b9\u4e0a\u6267\u884c\u7684\u903b\u8f91\u3002\u8fde\u63a5\u70b9\u662fAOP\u4e2d\u4e00\u4e2a\u57fa\u672c\u7684\u6982\u5ff5\uff0c\u901a\u8fc7\u5b83\uff0c\u5207\u9762\u53ef\u4ee5\u5b9a\u4e49\u5728\u7a0b\u5e8f\u6267\u884c\u7684\u54ea\u4e9b\u4f4d\u7f6e\u6267\u884c\u4f55\u79cd\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9762\u5411\u5207\u9762\u7f16\u7a0b\uff08AOP\uff09\u4e2d\uff0c\u8fde\u63a5\u70b9\uff08Join Point\uff09\u662f\u5728\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u80fd\u591f\u63d2\u5165\u5207\u9762\u7684\u70b9\u3002\u8fde\u63a5\u70b9\u53ef\u4ee5\u662f\u65b9\u6cd5 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-11598","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=11598"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11598\/revisions"}],"predecessor-version":[{"id":17090,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11598\/revisions\/17090"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=11598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=11598"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=11598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}