{"id":261,"date":"2015-05-26T23:43:42","date_gmt":"2015-05-26T15:43:42","guid":{"rendered":"http:\/\/weitaoc.com\/?p=261"},"modified":"2015-05-28T21:09:51","modified_gmt":"2015-05-28T13:09:51","slug":"%e4%b8%80%e7%af%87%e8%ae%b2%e8%a7%a3%e9%9d%9e%e5%b8%b8%e7%bb%86%e8%87%b4%e7%9a%84%e6%96%87%e7%ab%a0-spring-aop-%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86%e4%b8%8e-cglib-%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"http:\/\/weitaoc.com\/?p=261","title":{"rendered":"\u4e00\u7bc7\u8bb2\u89e3\u975e\u5e38\u7ec6\u81f4\u7684\u6587\u7ae0-Spring AOP \u5b9e\u73b0\u539f\u7406\u4e0e CGLIB \u5e94\u7528"},"content":{"rendered":"<p><strong>\u7b80\u4ecb\uff1a<\/strong>\u00a0AOP\uff08Aspect Orient Programming\uff09\uff0c\u4e5f\u5c31\u662f\u9762\u5411\u65b9\u9762\u7f16\u7a0b\uff0c\u4f5c\u4e3a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4e00\u79cd\u8865\u5145\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u7cfb\u7edf\u4e2d\u5206\u5e03\u4e8e\u5404\u4e2a\u6a21\u5757\uff08\u4e0d\u540c\u65b9\u6cd5\uff09\u4e2d\u7684\u4ea4\u53c9\u5173\u6ce8\u70b9\u7684\u95ee\u9898\uff0c\u5728 Java EE \u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u901a\u8fc7 AOP \u6765\u5904\u7406\u4e00\u4e9b\u5177\u6709\u6a2a\u5207\u6027\u8d28\u7684\u7cfb\u7edf\u7ea7\u670d\u52a1\uff0c\u5982\u4e8b\u52a1\u7ba1\u7406\u3001\u5b89\u5168\u68c0\u67e5\u3001\u7f13\u5b58\u3001\u5bf9\u8c61\u6c60\u7ba1\u7406\u7b49\u3002AOP \u5b9e\u73b0\u7684\u5173\u952e\u5c31\u5728\u4e8e AOP \u6846\u67b6\u81ea\u52a8\u521b\u5efa\u7684 AOP \u4ee3\u7406\uff0cAOP \u4ee3\u7406\u4e3b\u8981\u5206\u4e3a\u9759\u6001\u4ee3\u7406\u548c\u52a8\u6001\u4ee3\u7406\u4e24\u5927\u7c7b\uff0c\u9759\u6001\u4ee3\u7406\u4ee5 AspectJ \u4e3a\u4ee3\u8868\uff1b\u800c\u52a8\u6001\u4ee3\u7406\u5219\u4ee5 Spring AOP \u4e3a\u4ee3\u8868\u3002\u672c\u6587\u4f1a\u4ece AspectJ \u5206\u6790\u8d77\uff0c\u9010\u6e10\u6df1\u5165\uff0c\u5e76\u4ecb\u7ecd CGLIB \u6765\u4ecb\u7ecd Spring AOP \u6846\u67b6\u7684\u5b9e\u73b0\u539f\u7406\u3002<\/p>\n<p>AOP\uff08Aspect Orient Programming\uff09\uff0c\u4f5c\u4e3a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4e00\u79cd\u8865\u5145\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5904\u7406\u4e00\u4e9b\u5177\u6709\u6a2a\u5207\u6027\u8d28\u7684\u7cfb\u7edf\u7ea7\u670d\u52a1\uff0c\u5982\u4e8b\u52a1\u7ba1\u7406\u3001\u5b89\u5168\u68c0\u67e5\u3001\u7f13\u5b58\u3001\u5bf9\u8c61\u6c60\u7ba1\u7406\u7b49\u3002 AOP \u5b9e\u73b0\u7684\u5173\u952e\u5c31\u5728\u4e8e AOP \u6846\u67b6\u81ea\u52a8\u521b\u5efa\u7684 AOP \u4ee3\u7406\uff0cAOP \u4ee3\u7406\u5219\u53ef\u5206\u4e3a\u9759\u6001\u4ee3\u7406\u548c\u52a8\u6001\u4ee3\u7406\u4e24\u5927\u7c7b\uff0c\u5176\u4e2d\u9759\u6001\u4ee3\u7406\u662f\u6307\u4f7f\u7528 AOP \u6846\u67b6\u63d0\u4f9b\u7684\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\uff0c\u4ece\u800c\u5728\u7f16\u8bd1\u9636\u6bb5\u5c31\u53ef\u751f\u6210 AOP \u4ee3\u7406\u7c7b\uff0c\u56e0\u6b64\u4e5f\u79f0\u4e3a\u7f16\u8bd1\u65f6\u589e\u5f3a\uff1b\u800c\u52a8\u6001\u4ee3\u7406\u5219\u5728\u8fd0\u884c\u65f6\u501f\u52a9\u4e8e JDK \u52a8\u6001\u4ee3\u7406\u3001CGLIB \u7b49\u5728\u5185\u5b58\u4e2d\u201c\u4e34\u65f6\u201d\u751f\u6210 AOP \u52a8\u6001\u4ee3\u7406\u7c7b\uff0c\u56e0\u6b64\u4e5f\u88ab\u79f0\u4e3a\u8fd0\u884c\u65f6\u589e\u5f3a\u3002<\/p>\n<p><strong>AOP \u7684\u5b58\u5728\u4ef7\u503c<\/strong><\/p>\n<p>\u5728\u4f20\u7edf OOP \u7f16\u7a0b\u91cc\u4ee5\u5bf9\u8c61\u4e3a\u6838\u5fc3\uff0c\u6574\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u7531\u7cfb\u5217\u76f8\u4e92\u4f9d\u8d56\u7684\u5bf9\u8c61\u6240\u7ec4\u6210\uff0c\u800c\u8fd9\u4e9b\u5bf9\u8c61\u5c06\u88ab\u62bd\u8c61\u6210\u4e00\u4e2a\u4e00\u4e2a\u7684\u7c7b\uff0c\u5e76\u5141\u8bb8\u4f7f\u7528\u7c7b\u7ee7\u627f\u6765\u7ba1\u7406\u7c7b\u4e0e\u7c7b\u4e4b\u95f4\u4e00\u822c\u5230\u7279\u6b8a\u7684\u5173\u7cfb\u3002\u968f\u7740\u8f6f\u4ef6\u89c4\u6a21\u7684\u589e\u5927\uff0c\u5e94\u7528\u7684\u9010\u6e10\u5347\u7ea7\uff0c\u6162\u6162\u51fa\u73b0\u4e86\u4e00\u4e9b OOP \u5f88\u96be\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u3001\u62bd\u8c61\u51fa\u4e00\u7cfb\u5217\u5177\u6709\u4e00\u5b9a\u5c5e\u6027\u4e0e\u884c\u4e3a\u7684\u5bf9\u8c61\uff0c\u5e76\u901a\u8fc7\u8fd9\u4e9b\u5bf9\u8c61\u4e4b\u95f4\u7684\u534f\u4f5c\u6765\u5f62\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u8f6f\u4ef6\u529f\u80fd\u3002\u7531\u4e8e\u5bf9\u8c61\u53ef\u4ee5\u7ee7\u627f\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u628a \u5177\u6709\u76f8\u540c\u529f\u80fd\u6216\u76f8\u540c\u7279\u6027\u7684\u5c5e\u6027\u62bd\u8c61\u5230\u4e00\u4e2a\u5c42\u6b21\u5206\u660e\u7684\u7c7b\u7ed3\u6784\u4f53\u7cfb\u4e2d\u3002\u968f\u7740\u8f6f\u4ef6\u89c4\u8303\u7684\u4e0d\u65ad\u6269\u5927\uff0c\u4e13\u4e1a\u5316\u5206\u5de5\u8d8a\u6765\u8d8a\u7cfb\u5217\uff0c\u4ee5\u53ca OOP \u5e94\u7528\u5b9e\u8df5\u7684\u4e0d\u65ad\u589e\u591a\uff0c\u968f\u4e4b\u4e5f\u66b4\u9732\u51fa\u4e86\u4e00\u4e9b OOP \u65e0\u6cd5\u5f88\u597d\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<p>\u73b0\u5728\u5047\u8bbe\u7cfb\u7edf\u4e2d\u6709 3 \u6bb5\u5b8c\u5168\u76f8\u4f3c\u7684\u4ee3\u7801\uff0c\u8fd9\u4e9b\u4ee3\u7801\u901a\u5e38\u4f1a\u91c7\u7528\u201c\u590d\u5236\u201d\u3001\u201c\u7c98\u8d34\u201d\u65b9\u5f0f\u6765\u5b8c\u6210\uff0c\u901a\u8fc7\u8fd9\u79cd\u201c\u590d\u5236\u201d\u3001\u201c\u7c98\u8d34\u201d\u65b9\u5f0f\u5f00\u53d1\u51fa\u6765\u7684\u8f6f\u4ef6\u5982\u56fe 1 \u6240\u793a\u3002<\/p>\n<p style=\"text-align: center;\"><strong>\u56fe 1.\u591a\u4e2a\u5730\u65b9\u5305\u542b\u76f8\u540c\u4ee3\u7801\u7684\u8f6f\u4ef6<\/strong><\/p>\n<p><a href=\"http:\/\/weitaoc.com\/archives\/261\/1-10\" rel=\"attachment wp-att-262\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-262 aligncenter\" src=\"http:\/\/weitaoc.com\/wp-content\/uploads\/2015\/05\/1.jpg\" alt=\"1\" width=\"481\" height=\"415\" \/><\/a><\/p>\n<p>\u770b\u5230\u5982\u56fe 1 \u6240\u793a\u7684\u793a\u610f\u56fe\uff0c\u53ef\u80fd\u6709\u7684\u8bfb\u8005\u5df2\u7ecf\u53d1\u73b0\u4e86\u8fd9\u79cd\u505a\u6cd5\u7684\u4e0d\u8db3\u4e4b\u5904\uff1a\u5982\u679c\u6709\u4e00\u5929\uff0c\u56fe 1 \u4e2d\u7684\u6df1\u8272\u4ee3\u7801\u6bb5\u9700\u8981\u4fee\u6539\uff0c\u90a3\u662f\u4e0d\u662f\u8981\u6253\u5f00 3 \u4e2a\u5730\u65b9\u7684\u4ee3\u7801\u8fdb\u884c\u4fee\u6539\uff1f\u5982\u679c\u4e0d\u662f 3 \u4e2a\u5730\u65b9\u5305\u542b\u8fd9\u6bb5\u4ee3\u7801\uff0c\u800c\u662f 100 \u4e2a\u5730\u65b9\uff0c\u751a\u81f3\u662f 1000 \u4e2a\u5730\u65b9\u5305\u542b\u8fd9\u6bb5\u4ee3\u7801\u6bb5\uff0c\u90a3\u4f1a\u662f\u4ec0\u4e48\u540e\u679c\uff1f<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u91c7\u7528\u5c06\u5982\u56fe 1 \u6240\u793a\u7684\u6df1\u8272\u4ee3\u7801\u90e8\u5206\u5b9a\u4e49\u6210\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7136\u540e\u5728 3 \u4e2a\u4ee3\u7801\u6bb5\u4e2d\u5206\u522b\u8c03\u7528\u8be5\u65b9\u6cd5\u5373\u53ef\u3002\u5728\u8fd9\u79cd\u65b9\u5f0f\u4e0b\uff0c\u8f6f\u4ef6\u7cfb\u7edf\u7684\u7ed3\u6784\u5982\u56fe 2 \u6240\u793a\u3002<\/p>\n<p style=\"text-align: center;\"><strong>\u56fe 2 \u901a\u8fc7\u65b9\u6cd5\u8c03\u7528\u5b9e\u73b0\u7cfb\u7edf\u529f\u80fd<\/strong><\/p>\n<p><a href=\"http:\/\/weitaoc.com\/?attachment_id=274\" rel=\"attachment wp-att-262\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-262 aligncenter\" src=\"http:\/\/weitaoc.com\/wp-content\/uploads\/2015\/05\/11.jpg\" alt=\"1\" width=\"433\" height=\"419\" \/><\/a><\/p>\n<p>\u5bf9\u4e8e\u5982\u56fe 2 \u6240\u793a\u7684\u8f6f\u4ef6\u7cfb\u7edf\uff0c\u5982\u679c\u9700\u8981\u4fee\u6539\u6df1\u8272\u90e8\u5206\u7684\u4ee3\u7801\uff0c\u53ea\u8981\u4fee\u6539\u4e00\u4e2a\u5730\u65b9\u5373\u53ef\uff0c\u4e0d\u7ba1\u6574\u4e2a\u7cfb\u7edf\u4e2d\u6709\u591a\u5c11\u5730\u65b9\u8c03\u7528\u4e86\u8be5\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u65e0\u987b\u4fee\u6539\u8fd9\u4e9b\u5730\u65b9\uff0c\u53ea\u9700\u4fee\u6539\u88ab\u8c03\u7528\u7684\u65b9\u6cd5\u5373\u53ef\u2014\u2014\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u5927\u5927\u964d\u4f4e\u4e86\u8f6f\u4ef6\u540e\u671f\u7ef4\u62a4\u7684\u590d\u6742\u5ea6\u3002<\/p>\n<p>\u5bf9\u4e8e\u5982\u56fe 2 \u6240\u793a\u7684\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u4f9d\u7136\u9700\u8981\u663e\u5f0f\u8c03\u7528\u6df1\u8272\u65b9\u6cd5\uff0c\u8fd9\u6837\u505a\u80fd\u591f\u89e3\u51b3\u5927\u90e8\u5206\u5e94\u7528\u573a\u666f\u3002\u4f46\u5bf9\u4e8e\u4e00\u4e9b\u66f4\u7279\u6b8a\u7684\u60c5\u51b5\uff1a\u5e94\u7528\u9700\u8981\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u5f7b\u5e95\u4e0e\u6df1\u8272\u65b9\u6cd5\u5206\u79bb\u2014\u2014\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u65e0\u987b\u76f4\u63a5\u8c03\u7528\u6df1\u8272\u65b9\u6cd5\uff0c\u90a3\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n<p>\u56e0\u4e3a\u8f6f\u4ef6\u7cfb\u7edf\u9700\u6c42\u53d8\u66f4\u662f\u5f88\u9891\u7e41\u7684\u4e8b\u60c5\uff0c\u7cfb\u7edf\u524d\u671f\u8bbe\u8ba1\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u65f6\u53ea\u5b9e\u73b0\u4e86\u6838\u5fc3\u4e1a\u52a1\u529f\u80fd\uff0c\u8fc7\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u90fd\u589e\u52a0\u4e8b\u52a1\u63a7\u5236\uff1b\u53c8\u8fc7\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u5ba2\u6237\u63d0\u51fa\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u9700\u8981\u8fdb\u884c\u7528\u6237\u5408\u6cd5\u6027\u9a8c\u8bc1\uff0c\u53ea\u6709\u5408\u6cd5\u7684\u7528\u6237\u624d\u80fd\u6267\u884c\u8fd9\u4e9b\u65b9\u6cd5\uff1b\u53c8\u8fc7\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u5ba2\u6237\u53c8\u63d0\u51fa\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u5e94\u8be5\u589e\u52a0\u65e5\u5fd7\u8bb0\u5f55\uff1b\u53c8\u8fc7\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u5ba2\u6237\u53c8\u63d0\u51fa\u2026\u2026\u9762\u5bf9\u8fd9\u6837\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u600e\u4e48\u529e\uff1f\u901a\u5e38\u6709\u4e24\u79cd\u505a\u6cd5\uff1a<\/p>\n<p>\u25cf \u6839\u636e\u9700\u6c42\u8bf4\u660e\u4e66\uff0c\u76f4\u63a5\u62d2\u7edd\u5ba2\u6237\u8981\u6c42\u3002<\/p>\n<p>\u25cf\u00a0\u62e5\u62b1\u9700\u6c42\uff0c\u6ee1\u8db3\u5ba2\u6237\u7684\u9700\u6c42\u3002<\/p>\n<p>\u7b2c\u4e00\u79cd\u505a\u6cd5\u663e\u7136\u4e0d\u597d\uff0c\u5ba2\u6237\u662f\u4e0a\u5e1d\uff0c\u6211\u4eec\u5e94\u8be5\u5c3d\u91cf\u6ee1\u8db3\u5ba2\u6237\u7684\u9700\u6c42\u3002\u901a\u5e38\u4f1a\u91c7\u7528\u7b2c\u4e8c\u79cd\u505a\u6cd5\uff0c\u90a3\u5982\u4f55\u89e3\u51b3\u5462\uff1f\u662f\u4e0d\u662f\u6bcf\u6b21\u5148\u5b9a\u4e49\u4e00\u4e2a\u65b0\u65b9\u6cd5\uff0c\u7136\u540e\u4fee\u6539\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3\uff0c\u589e\u52a0\u8c03\u7528\u65b0\u65b9\u6cd5\uff1f\u8fd9\u6837\u505a\u7684\u5de5\u4f5c\u91cf\u4e5f\u4e0d\u5c0f\u554a\uff01\u6211\u4eec\u5e0c\u671b\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u6cd5\uff1a\u6211\u4eec\u53ea\u8981\u5b9a\u4e49\u8be5\u65b9\u6cd5\uff0c\u65e0\u987b\u5728\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u4e2d\u663e\u5f0f\u8c03\u7528\u5b83\uff0c\u7cfb\u7edf\u4f1a\u201c\u81ea\u52a8\u201d\u6267\u884c\u8be5\u7279\u6b8a\u65b9\u6cd5\u3002<\/p>\n<p>\u4e0a\u9762\u60f3\u6cd5\u542c\u8d77\u6765\u5f88\u795e\u5947\uff0c\u751a\u81f3\u6709\u4e00\u4e9b\u4e0d\u5207\u5b9e\u9645\uff0c\u4f46\u5176\u5b9e\u662f\u5b8c\u5168\u53ef\u4ee5\u5b9e\u73b0\u7684\uff0c\u5b9e\u73b0\u8fd9\u4e2a\u9700\u6c42\u7684\u6280\u672f\u5c31\u662f AOP\u3002AOP \u4e13\u95e8\u7528\u4e8e\u5904\u7406\u7cfb\u7edf\u4e2d\u5206\u5e03\u4e8e\u5404\u4e2a\u6a21\u5757\uff08\u4e0d\u540c\u65b9\u6cd5\uff09\u4e2d\u7684\u4ea4\u53c9\u5173\u6ce8\u70b9\u7684\u95ee\u9898\uff0c\u5728 Java EE \u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u901a\u8fc7 AOP \u6765\u5904\u7406\u4e00\u4e9b\u5177\u6709\u6a2a\u5207\u6027\u8d28\u7684\u7cfb\u7edf\u7ea7\u670d\u52a1\uff0c\u5982\u4e8b\u52a1\u7ba1\u7406\u3001\u5b89\u5168\u68c0\u67e5\u3001\u7f13\u5b58\u3001\u5bf9\u8c61\u6c60\u7ba1\u7406\u7b49\uff0cAOP \u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u975e\u5e38\u5e38\u7528\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u4f7f\u7528 AspectJ \u7684\u7f16\u8bd1\u65f6\u589e\u5f3a\u8fdb\u884c AOP<\/strong><\/p>\n<p>AspectJ \u662f\u4e00\u4e2a\u57fa\u4e8e Java \u8bed\u8a00\u7684 AOP \u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684 AOP \u529f\u80fd\uff0c\u5176\u4ed6\u5f88\u591a AOP \u6846\u67b6\u90fd\u501f\u9274\u6216\u91c7\u7eb3\u5176\u4e2d\u7684\u4e00\u4e9b\u601d\u60f3\u3002<\/p>\n<p>AspectJ \u662f Java \u8bed\u8a00\u7684\u4e00\u4e2a AOP \u5b9e\u73b0\uff0c\u5176\u4e3b\u8981\u5305\u62ec\u4e24\u4e2a\u90e8\u5206\uff1a\u7b2c\u4e00\u4e2a\u90e8\u5206\u5b9a\u4e49\u4e86\u5982\u4f55\u8868\u8fbe\u3001\u5b9a\u4e49 AOP \u7f16\u7a0b\u4e2d\u7684\u8bed\u6cd5\u89c4\u8303\uff0c\u901a\u8fc7\u8fd9\u5957\u8bed\u8a00\u89c4\u8303\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u7528 AOP \u6765\u89e3\u51b3 Java \u8bed\u8a00\u4e2d\u5b58\u5728\u7684\u4ea4\u53c9\u5173\u6ce8\u70b9\u95ee\u9898\uff1b\u53e6\u4e00\u4e2a\u90e8\u5206\u662f\u5de5\u5177\u90e8\u5206\uff0c\u5305\u62ec\u7f16\u8bd1\u5668\u3001\u8c03\u8bd5\u5de5\u5177\u7b49\u3002<\/p>\n<p>AspectJ \u662f\u6700\u65e9\u3001\u529f\u80fd\u6bd4\u8f83\u5f3a\u5927\u7684 AOP \u5b9e\u73b0\u4e4b\u4e00\uff0c\u5bf9\u6574\u5957 AOP \u673a\u5236\u90fd\u6709\u8f83\u597d\u7684\u5b9e\u73b0\uff0c\u5f88\u591a\u5176\u4ed6\u8bed\u8a00\u7684 AOP \u5b9e\u73b0\uff0c\u4e5f\u501f\u9274\u6216\u91c7\u7eb3\u4e86 AspectJ \u4e2d\u5f88\u591a\u8bbe\u8ba1\u3002\u5728 Java \u9886\u57df\uff0cAspectJ \u4e2d\u7684\u5f88\u591a\u8bed\u6cd5\u7ed3\u6784\u57fa\u672c\u4e0a\u5df2\u6210\u4e3a AOP \u9886\u57df\u7684\u6807\u51c6\u3002<\/p>\n<p>\u4e0b\u8f7d\u3001\u5b89\u88c5 AspectJ \u6bd4\u8f83\u7b80\u5355\uff0c\u8bfb\u8005\u767b\u5f55 AspectJ \u5b98\u7f51\uff08http:\/\/www.eclipse.org\/aspectj\uff09\uff0c\u5373\u53ef\u4e0b\u8f7d\u5230\u4e00\u4e2a\u53ef\u6267\u884c\u7684 JAR \u5305\uff0c\u4f7f\u7528 java -jar aspectj-1.x.x.jar \u547d\u4ee4\u3001\u591a\u6b21\u5355\u51fb\u201cNext\u201d\u6309\u94ae\u5373\u53ef\u6210\u529f\u5b89\u88c5 AspectJ\u3002<\/p>\n<p>\u6210\u529f\u5b89\u88c5\u4e86 AspectJ \u4e4b\u540e\uff0c\u5c06\u4f1a\u5728 E:\\Java\\AOP\\aspectj1.6 \u8def\u5f84\u4e0b\uff08AspectJ \u7684\u5b89\u88c5\u8def\u5f84\uff09\u770b\u5230\u5982\u4e0b\u6587\u4ef6\u7ed3\u6784\uff1a<\/p>\n<p>\u25cf\u00a0bin\uff1a\u8be5\u8def\u5f84\u4e0b\u5b58\u653e\u4e86 aj\u3001aj5\u3001ajc\u3001ajdoc\u3001ajbrowser \u7b49\u547d\u4ee4\uff0c\u5176\u4e2d ajc \u547d\u4ee4\u6700\u5e38\u7528\uff0c\u5b83\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e javac\uff0c\u7528\u4e8e\u5bf9\u666e\u901a Java \u7c7b\u8fdb\u884c\u7f16\u8bd1\u65f6\u589e\u5f3a\u3002<\/p>\n<p>\u25cf\u00a0docs\uff1a\u8be5\u8def\u5f84\u4e0b\u5b58\u653e\u4e86 AspectJ \u7684\u4f7f\u7528\u8bf4\u660e\u3001\u53c2\u8003\u624b\u518c\u3001API \u6587\u6863\u7b49\u6587\u6863\u3002<\/p>\n<p>\u25cf\u00a0lib\uff1a\u8be5\u8def\u5f84\u4e0b\u7684 4 \u4e2a JAR \u6587\u4ef6\u662f AspectJ \u7684\u6838\u5fc3\u7c7b\u5e93\u3002<\/p>\n<p>\u25cf\u00a0\u76f8\u5173\u6388\u6743\u6587\u4ef6\u3002<\/p>\n<p>\u4e00\u4e9b\u6587\u6863\u3001AspectJ \u5165\u95e8\u4e66\u7c4d\uff0c\u4e00\u8c08\u5230\u4f7f\u7528 AspectJ\uff0c\u5c31\u8ba4\u4e3a\u5fc5\u987b\u4f7f\u7528 Eclipse \u5de5\u5177\uff0c\u4f3c\u4e4e\u79bb\u5f00\u4e86\u8be5\u5de5\u5177\u5c31\u65e0\u6cd5\u4f7f\u7528 AspectJ \u4e86\u3002<\/p>\n<p>\u867d\u7136 AspectJ \u662f Eclipse \u57fa\u91d1\u7ec4\u7ec7\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u800c\u4e14\u63d0\u4f9b\u4e86 Eclipse \u7684 AJDT \u63d2\u4ef6\uff08AspectJ Development Tools\uff09\u6765\u5f00\u53d1 AspectJ \u5e94\u7528\uff0c\u4f46 AspectJ \u7edd\u5bf9\u65e0\u987b\u4f9d\u8d56\u4e8e Eclipse \u5de5\u5177\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cAspectJ \u7684\u7528\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u50cf\u6211\u4eec\u4f7f\u7528 JDK \u7f16\u8bd1\u3001\u8fd0\u884c Java \u7a0b\u5e8f\u4e00\u6837\u3002\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u7a0b\u5e8f\u6765\u793a\u8303 AspectJ \u7684\u7528\u6cd5\uff0c\u5e76\u5206\u6790 AspectJ \u5982\u4f55\u5728\u7f16\u8bd1\u65f6\u8fdb\u884c\u589e\u5f3a\u3002<\/p>\n<p>\u9996\u5148\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684 Java \u7c7b\uff0c\u8fd9\u4e2a Java \u7c7b\u7528\u4e8e\u6a21\u62df\u4e00\u4e2a\u4e1a\u52a1\u7ec4\u4ef6\u3002<\/p>\n<p><strong>\u6e05\u5355 1.Hello.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> Hello<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u65b9\u6cd5\uff0c\u6a21\u62df\u5e94\u7528\u4e2d\u7684\u4e1a\u52a1\u903b\u8f91\u65b9\u6cd5<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> sayHello<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;Hello AspectJ!&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u4e3b\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u7684\u5165\u53e3<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> args<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\nHello h <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> Hello<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nh.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762 Hello \u7c7b\u6a21\u62df\u4e86\u4e00\u4e2a\u4e1a\u52a1\u903b\u8f91\u7ec4\u4ef6\uff0c\u7f16\u8bd1\u3001\u8fd0\u884c\u8be5 Java \u7a0b\u5e8f\uff0c\u8fd9\u4e2a\u7ed3\u679c\u662f\u6ca1\u6709\u4efb\u4f55\u60ac\u5ff5\u7684\uff0c\u7a0b\u5e8f\u5c06\u5728\u63a7\u5236\u53f0\u6253\u5370\u201cHello AspectJ\u201d\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u5047\u8bbe\u73b0\u5728\u5ba2\u6237\u9700\u8981\u5728\u6267\u884c sayHello() \u65b9\u6cd5\u4e4b\u524d\u542f\u52a8\u4e8b\u52a1\uff0c\u5f53\u8be5\u65b9\u6cd5\u6267\u884c\u7ed3\u675f\u65f6\u5173\u95ed\u4e8b\u52a1\uff0c\u5728\u4f20\u7edf\u7f16\u7a0b\u6a21\u5f0f\u4e0b\uff0c\u6211\u4eec\u5fc5\u987b\u624b\u52a8\u4fee\u6539 sayHello() \u65b9\u6cd5\u2014\u2014\u5982\u679c\u6539\u4e3a\u4f7f\u7528 AspectJ\uff0c\u5219\u53ef\u4ee5\u65e0\u987b\u4fee\u6539\u4e0a\u9762\u7684 sayHello() \u65b9\u6cd5\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u7279\u6b8a\u7684 Java \u7c7b\u3002<\/p>\n<p><strong>\u6e05\u5355 2.TxAspect.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> aspect TxAspect<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u6307\u5b9a\u6267\u884c Hello.sayHello() \u65b9\u6cd5\u65f6\u6267\u884c\u4e0b\u9762\u4ee3\u7801\u5757<\/span><br \/>\n<span style=\"color: #000066; font-weight: bold;\">void<\/span> around<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">:<\/span>call<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #000066; font-weight: bold;\">void<\/span> Hello.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u5f00\u59cb\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nproceed<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u4e8b\u52a1\u7ed3\u675f ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u53ef\u80fd\u8bfb\u8005\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u4e0a\u9762\u7c7b\u6587\u4ef6\u4e2d\u4e0d\u662f\u4f7f\u7528 class\u3001interface\u3001enum \u5728\u5b9a\u4e49 Java \u7c7b\uff0c\u800c\u662f\u4f7f\u7528\u4e86 aspect \u2014\u2014\u96be\u9053 Java \u8bed\u8a00\u53c8\u65b0\u589e\u4e86\u5173\u952e\u5b57\uff1f\u6ca1\u6709\uff01\u4e0a\u9762\u7684 TxAspect \u6839\u672c\u4e0d\u662f\u4e00\u4e2a Java \u7c7b\uff0c\u6240\u4ee5 aspect \u4e5f\u4e0d\u662f Java \u652f\u6301\u7684\u5173\u952e\u5b57\uff0c\u5b83\u53ea\u662f AspectJ \u624d\u80fd\u8bc6\u522b\u7684\u5173\u952e\u5b57\u3002<\/p>\n<p>\u4e0a\u9762\u7c97\u4f53\u5b57\u4ee3\u7801\u4e5f\u4e0d\u662f\u65b9\u6cd5\uff0c\u5b83\u53ea\u662f\u6307\u5b9a\u5f53\u7a0b\u5e8f\u6267\u884c Hello \u5bf9\u8c61\u7684 sayHello() \u65b9\u6cd5\u65f6\uff0c\u7cfb\u7edf\u5c06\u6539\u4e3a\u6267\u884c\u7c97\u4f53\u5b57\u4ee3\u7801\u7684\u82b1\u62ec\u53f7\u4ee3\u7801\u5757\uff0c\u5176\u4e2d proceed() \u4ee3\u8868\u56de\u8c03\u539f\u6765\u7684 sayHello() \u65b9\u6cd5\u3002<\/p>\n<p>\u6b63\u5982\u524d\u9762\u63d0\u5230\u7684\uff0cJava \u65e0\u6cd5\u8bc6\u522b TxAspect.java \u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u4f7f\u7528 ajc.exe \u547d\u4ee4\u6765\u7f16\u8bd1\u4e0a\u9762\u7684 Java \u7a0b\u5e8f\u3002\u4e3a\u4e86\u80fd\u5728\u547d\u4ee4\u884c\u4f7f\u7528 ajc.exe \u547d\u4ee4\uff0c\u9700\u8981\u628a AspectJ \u5b89\u88c5\u76ee\u5f55\u4e0b\u7684 bin \u8def\u5f84\uff08\u6bd4\u5982 E:\\Java\\AOP\\aspectj1.6\\bin \u76ee\u5f55\uff09\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684 PATH \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u63a5\u4e0b\u6765\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\uff1a<\/p>\n<p>ajc -d . Hello.java TxAspect.java<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u628a ajc.exe \u7406\u89e3\u6210 javac.exe \u547d\u4ee4\uff0c\u90fd\u7528\u4e8e\u7f16\u8bd1 Java \u7a0b\u5e8f\uff0c\u533a\u522b\u662f ajc.exe \u547d\u4ee4\u53ef\u8bc6\u522b AspectJ \u7684\u8bed\u6cd5\uff1b\u4ece\u8fd9\u4e2a\u610f\u4e49\u4e0a\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 ajc.exe \u5f53\u6210\u4e00\u4e2a\u589e\u5f3a\u7248\u7684 javac.exe \u547d\u4ee4\u3002<\/p>\n<p>\u8fd0\u884c\u8be5 Hello \u7c7b\u4f9d\u7136\u65e0\u987b\u4efb\u4f55\u6539\u53d8\uff0c\u56e0\u4e3a Hello \u7c7b\u4f4d\u4e8e lee \u5305\u4e0b\u3002\u7a0b\u5e8f\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fd0\u884c Hello \u7c7b\uff1a<\/p>\n<p>java lee.Hello<\/p>\n<p>\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u5c06\u770b\u5230\u4e00\u4e2a\u4ee4\u4eba\u60ca\u559c\u7684\u7ed3\u679c\uff1a<\/p>\n<p>\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>Hello AspectJ!<\/p>\n<p>\u4e8b\u52a1\u7ed3\u675f \u2026<\/p>\n<p>\u4ece\u4e0a\u9762\u8fd0\u884c\u7ed3\u679c\u6765\u770b\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u4e0d\u5bf9 Hello.java \u7c7b\u8fdb\u884c\u4efb\u4f55\u4fee\u6539\uff0c\u540c\u65f6\u53c8\u53ef\u4ee5\u6ee1\u8db3\u5ba2\u6237\u7684\u9700\u6c42\uff1a\u4e0a\u9762\u7a0b\u5e8f\u53ea\u662f\u5728\u63a7\u5236\u53f0\u6253\u5370\u201c\u5f00\u59cb\u4e8b\u52a1 \u2026\u201d\u3001\u201c\u7ed3\u675f\u4e8b\u52a1 \u2026\u201d\u6765\u6a21\u62df\u4e86\u4e8b\u52a1\u64cd\u4f5c\uff0c\u5b9e\u9645\u4e0a\u6211\u4eec\u53ef\u7528\u5b9e\u9645\u7684\u4e8b\u52a1\u64cd\u4f5c\u4ee3\u7801\u6765\u4ee3\u66ff\u8fd9\u4e24\u884c\u7b80\u5355\u7684\u8bed\u53e5\uff0c\u8fd9\u5c31\u53ef\u4ee5\u6ee1\u8db3\u5ba2\u6237\u9700\u6c42\u4e86\u3002<\/p>\n<p>\u5982\u679c\u5ba2\u6237\u518d\u6b21\u63d0\u51fa\u65b0\u9700\u6c42\uff0c\u9700\u8981\u5728 sayHello() \u65b9\u6cd5\u540e\u589e\u52a0\u8bb0\u5f55\u65e5\u5fd7\u7684\u529f\u80fd\uff0c\u90a3\u4e5f\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u518d\u5b9a\u4e49\u4e00\u4e2a LogAspect\uff0c\u7a0b\u5e8f\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u6e05\u5355 3.LogAspect.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> aspect LogAspect<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u4e00\u4e2a PointCut\uff0c\u5176\u540d\u4e3a logPointcut<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u8be5 PointCut \u5bf9\u5e94\u4e8e\u6307\u5b9a Hello \u5bf9\u8c61\u7684 sayHello \u65b9\u6cd5<\/span><br \/>\npointcut logPointcut<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">:<\/span>execution<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #000066; font-weight: bold;\">void<\/span> Hello.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5728 logPointcut \u4e4b\u540e\u6267\u884c\u4e0b\u9762\u4ee3\u7801\u5757<\/span><br \/>\nafter<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">:<\/span>logPointcut<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u8bb0\u5f55\u65e5\u5fd7 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762\u7a0b\u5e8f\u7684\u7c97\u4f53\u5b57\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a Pointcut\uff1alogPointcut \u2013 \u7b49\u540c\u4e8e\u6267\u884c Hello \u5bf9\u8c61\u7684 sayHello() \u65b9\u6cd5\uff0c\u5e76\u6307\u5b9a\u5728 logPointcut \u4e4b\u540e\u6267\u884c\u7b80\u5355\u7684\u4ee3\u7801\u5757\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728 sayHello() \u65b9\u6cd5\u4e4b\u540e\u6267\u884c\u6307\u5b9a\u4ee3\u7801\u5757\u3002\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u6765\u7f16\u8bd1\u4e0a\u9762\u7684 Java \u7a0b\u5e8f\uff1a<\/p>\n<p>ajc -d . *.java<\/p>\n<p>\u518d\u6b21\u8fd0\u884c Hello \u7c7b\uff0c\u5c06\u770b\u5230\u5982\u4e0b\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p>\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>Hello AspectJ!<\/p>\n<p>\u8bb0\u5f55\u65e5\u5fd7 \u2026<\/p>\n<p>\u4e8b\u52a1\u7ed3\u675f \u2026<\/p>\n<p>\u4ece\u4e0a\u9762\u8fd0\u884c\u7ed3\u679c\u6765\u770b\uff0c\u901a\u8fc7\u4f7f\u7528 AspectJ \u63d0\u4f9b\u7684 AOP \u652f\u6301\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a sayHello() \u65b9\u6cd5\u4e0d\u65ad\u589e\u52a0\u65b0\u529f\u80fd\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u5728\u5bf9 Hello \u7c7b\u6ca1\u6709\u4efb\u4f55\u4fee\u6539\u7684\u524d\u63d0\u4e0b\uff0c\u800c Hello \u7c7b\u80fd\u4e0d\u65ad\u5730\u3001\u52a8\u6001\u589e\u52a0\u65b0\u529f\u80fd\u5462\uff1f\u8fd9\u770b\u4e0a\u53bb\u5e76\u4e0d\u7b26\u5408 Java \u57fa\u672c\u8bed\u6cd5\u89c4\u5219\u554a\u3002\u5b9e\u9645\u4e0a\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Java \u7684\u53cd\u7f16\u8bd1\u5de5\u5177\u6765\u53cd\u7f16\u8bd1\u524d\u9762\u7a0b\u5e8f\u751f\u6210\u7684 Hello.class \u6587\u4ef6\uff0c\u53d1\u73b0 Hello.class \u6587\u4ef6\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u6e05\u5355 4.Hello.class<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">package<\/span> <span style=\"color: #006699;\">lee<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<br \/>\n<span style=\"color: #000000; font-weight: bold;\">import<\/span> <span style=\"color: #006699;\">java.io.PrintStream<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">import<\/span> <span style=\"color: #006699;\">org.aspectj.runtime.internal.AroundClosure<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> Hello<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> sayHello<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">try<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;Hello AspectJ!&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">&#125;<\/span> <span style=\"color: #000000; font-weight: bold;\">catch<\/span> <span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">Throwable<\/span> localThrowable<span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span><br \/>\nLogAspect.<span style=\"color: #006633;\">aspectOf<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>.<span style=\"color: #006633;\">ajc<\/span>$after$lee_LogAspect$1$9fd5dd97<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #000000; font-weight: bold;\">throw<\/span> localThrowable<span style=\"color: #339933;\">;<\/span> <span style=\"color: #009900;\">&#125;<\/span><br \/>\nLogAspect.<span style=\"color: #006633;\">aspectOf<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>.<span style=\"color: #006633;\">ajc<\/span>$after$lee_LogAspect$1$9fd5dd97<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<br \/>\n...<br \/>\n<br \/>\n<span style=\"color: #000000; font-weight: bold;\">private<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> <span style=\"color: #000000; font-weight: bold;\">final<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> sayHello_aroundBody1$advice<span style=\"color: #009900;\">&#40;<\/span>Hello target,<br \/>\nTxAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u5f00\u59cb\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nAroundClosure localAroundClosure <span style=\"color: #339933;\">=<\/span> ajc$aroundClosure<span style=\"color: #339933;\">;<\/span> sayHello_aroundBody0<span style=\"color: #009900;\">&#40;<\/span>target<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u4e8b\u52a1\u7ed3\u675f ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0d\u96be\u53d1\u73b0\u8fd9\u4e2a Hello.class \u6587\u4ef6\u4e0d\u662f\u7531\u539f\u6765\u7684 Hello.java \u6587\u4ef6\u7f16\u8bd1\u5f97\u5230\u7684\uff0c\u8be5 Hello.class \u91cc\u65b0\u589e\u4e86\u5f88\u591a\u5185\u5bb9\u2014\u2014\u8fd9\u8868\u660e AspectJ \u5728\u7f16\u8bd1\u65f6\u201c\u81ea\u52a8\u201d\u7f16\u8bd1\u5f97\u5230\u4e86\u4e00\u4e2a\u65b0\u7c7b\uff0c\u8fd9\u4e2a\u65b0\u7c7b\u589e\u5f3a\u4e86\u539f\u6709\u7684 Hello.java \u7c7b\u7684\u529f\u80fd\uff0c\u56e0\u6b64 AspectJ \u901a\u5e38\u88ab\u79f0\u4e3a\u7f16\u8bd1\u65f6\u589e\u5f3a\u7684 AOP \u6846\u67b6\u3002<\/p>\n<p>\u63d0\u793a\uff1a\u4e0e AspectJ \u76f8\u5bf9\u7684\u8fd8\u6709\u53e6\u5916\u4e00\u79cd AOP \u6846\u67b6\uff0c\u5b83\u4eec\u4e0d\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u5bf9\u76ee\u6807\u7c7b\u8fdb\u884c\u589e\u5f3a\uff0c\u800c\u662f\u8fd0\u884c\u65f6\u751f\u6210\u76ee\u6807\u7c7b\u7684\u4ee3\u7406\u7c7b\uff0c\u8be5\u4ee3\u7406\u7c7b\u8981\u4e48\u4e0e\u76ee\u6807\u7c7b\u5b9e\u73b0\u76f8\u540c\u7684\u63a5\u53e3\uff0c\u8981\u4e48\u662f\u76ee\u6807\u7c7b\u7684\u5b50\u7c7b\u2014\u2014\u603b\u4e4b\uff0c\u4ee3\u7406\u7c7b\u7684 \u5b9e\u4f8b\u53ef\u4f5c\u4e3a\u76ee\u6807\u7c7b\u7684\u5b9e\u4f8b\u6765\u4f7f\u7528\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7f16\u8bd1\u65f6\u589e\u5f3a\u7684 AOP \u6846\u67b6\u5728\u6027\u80fd\u4e0a\u66f4\u6709\u4f18\u52bf\u2014\u2014\u56e0\u4e3a\u8fd0\u884c\u65f6\u52a8\u6001\u589e\u5f3a\u7684 AOP \u6846\u67b6\u9700\u8981\u6bcf\u6b21\u8fd0\u884c\u65f6\u90fd\u8fdb\u884c\u52a8\u6001\u589e\u5f3a\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cAspectJ \u5141\u8bb8\u540c\u65f6\u4e3a\u591a\u4e2a\u65b9\u6cd5\u6dfb\u52a0\u65b0\u529f\u80fd\uff0c\u53ea\u8981\u6211\u4eec\u5b9a\u4e49 Pointcut \u65f6\u6307\u5b9a\u5339\u914d\u66f4\u591a\u7684\u65b9\u6cd5\u5373\u53ef\u3002\u5982\u4e0b\u7247\u6bb5\uff1a<\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\">pointcut xxxPointcut<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #339933;\">:<\/span>execution<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #000066; font-weight: bold;\">void<\/span> H<span style=\"color: #339933;\">*<\/span>.<span style=\"color: #006633;\">say<\/span><span style=\"color: #339933;\">*<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762\u7a0b\u5e8f\u4e2d\u7684 xxxPointcut \u5c06\u53ef\u4ee5\u5339\u914d\u6240\u6709\u4ee5 H \u5f00\u5934\u7684\u7c7b\u4e2d\u3001\u6240\u6709\u4ee5 say \u5f00\u5934\u7684\u65b9\u6cd5\uff0c\u4f46\u8be5\u65b9\u6cd5\u8fd4\u56de\u7684\u5fc5\u987b\u662f void\uff1b\u5982\u679c\u4e0d\u60f3\u5339\u914d\u4efb\u610f\u7684\u8fd4\u56de\u503c\u7c7b\u578b\uff0c\u5219\u53ef\u5c06\u4ee3\u7801\u6539\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff1a<\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\">pointcut xxxPointcut<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #339933;\">:<\/span>execution<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #339933;\">*<\/span> H<span style=\"color: #339933;\">*<\/span>.<span style=\"color: #006633;\">say<\/span><span style=\"color: #339933;\">*<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u5173\u4e8e\u5982\u4f55\u5b9a\u4e49 AspectJ \u4e2d\u7684 Aspect\u3001Pointcut \u7b49\uff0c\u8bfb\u8005\u53ef\u4ee5\u53c2\u8003 AspectJ \u5b89\u88c5\u8def\u5f84\u4e0b\u7684 doc \u76ee\u5f55\u91cc\u7684 quick5.pdf \u6587\u4ef6\u3002<\/p>\n<p><strong>\u4f7f\u7528 Spring AOP<\/strong><\/p>\n<p>\u4e0e AspectJ \u76f8\u540c\u7684\u662f\uff0cSpring AOP \u540c\u6837\u9700\u8981\u5bf9\u76ee\u6807\u7c7b\u8fdb\u884c\u589e\u5f3a\uff0c\u4e5f\u5c31\u662f\u751f\u6210\u65b0\u7684 AOP \u4ee3\u7406\u7c7b\uff1b\u4e0e AspectJ \u4e0d\u540c\u7684\u662f\uff0cSpring AOP \u65e0\u9700\u4f7f\u7528\u4efb\u4f55\u7279\u6b8a\u547d\u4ee4\u5bf9 Java \u6e90\u4ee3\u7801\u8fdb\u884c\u7f16\u8bd1\uff0c\u5b83\u91c7\u7528\u8fd0\u884c\u65f6\u52a8\u6001\u5730\u3001\u5728\u5185\u5b58\u4e2d\u4e34\u65f6\u751f\u6210\u201c\u4ee3\u7406\u7c7b\u201d\u7684\u65b9\u5f0f\u6765\u751f\u6210 AOP \u4ee3\u7406\u3002<\/p>\n<p>Spring \u5141\u8bb8\u4f7f\u7528 AspectJ Annotation \u7528\u4e8e\u5b9a\u4e49\u65b9\u9762\uff08Aspect\uff09\u3001\u5207\u5165\u70b9\uff08Pointcut\uff09\u548c\u589e\u5f3a\u5904\u7406\uff08Advice\uff09\uff0cSpring \u6846\u67b6\u5219\u53ef\u8bc6\u522b\u5e76\u6839\u636e\u8fd9\u4e9b Annotation \u6765\u751f\u6210 AOP \u4ee3\u7406\u3002Spring \u53ea\u662f\u4f7f\u7528\u4e86\u548c AspectJ 5 \u4e00\u6837\u7684\u6ce8\u89e3\uff0c\u4f46\u5e76\u6ca1\u6709\u4f7f\u7528 AspectJ \u7684\u7f16\u8bd1\u5668\u6216\u8005\u7ec7\u5165\u5668\uff08<em>Weaver<\/em>\uff09\uff0c\u5e95\u5c42\u4f9d\u7136\u4f7f\u7528\u7684\u662f Spring AOP\uff0c\u4f9d\u7136\u662f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u751f\u6210 AOP \u4ee3\u7406\uff0c\u5e76\u4e0d\u4f9d\u8d56\u4e8e AspectJ \u7684\u7f16\u8bd1\u5668\u6216\u8005\u7ec7\u5165\u5668\u3002<\/p>\n<p>\u7b80\u5355\u5730\u8bf4\uff0cSpring \u4f9d\u7136\u91c7\u7528\u8fd0\u884c\u65f6\u751f\u6210\u52a8\u6001\u4ee3\u7406\u7684\u65b9\u5f0f\u6765\u589e\u5f3a\u76ee\u6807\u5bf9\u8c61\uff0c\u6240\u4ee5\u5b83\u4e0d\u9700\u8981\u589e\u52a0\u989d\u5916\u7684\u7f16\u8bd1\uff0c\u4e5f\u4e0d\u9700\u8981 AspectJ \u7684\u7ec7\u5165\u5668\u652f\u6301\uff1b\u800c AspectJ \u5728\u91c7\u7528\u7f16\u8bd1\u65f6\u589e\u5f3a\uff0c\u6240\u4ee5 AspectJ \u9700\u8981\u4f7f\u7528\u81ea\u5df1\u7684\u7f16\u8bd1\u5668\u6765\u7f16\u8bd1 Java \u6587\u4ef6\uff0c\u8fd8\u9700\u8981\u7ec7\u5165\u5668\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u6211\u4eec\u5e0c\u671b\u5b8c\u5168\u542f\u52a8 Spring \u7684\u201c\u96f6\u914d\u7f6e\u201d\u529f\u80fd\uff0c\u5219\u8fd8\u9700\u8981\u542f\u7528 Spring \u7684\u201c\u96f6\u914d\u7f6e\u201d\u652f\u6301\uff0c\u8ba9 Spring \u81ea\u52a8\u641c\u7d22\u6307\u5b9a\u8def\u5f84\u4e0b Bean \u7c7b\u3002<\/p>\n<p>\u6240\u8c13\u81ea\u52a8\u589e\u5f3a\uff0c\u6307\u7684\u662f Spring \u4f1a\u5224\u65ad\u4e00\u4e2a\u6216\u591a\u4e2a\u65b9\u9762\u662f\u5426\u9700\u8981\u5bf9\u6307\u5b9a Bean \u8fdb\u884c\u589e\u5f3a\uff0c\u5e76\u636e\u6b64\u81ea\u52a8\u751f\u6210\u76f8\u5e94\u7684\u4ee3\u7406\uff0c\u4ece\u800c\u4f7f\u5f97\u589e\u5f3a\u5904\u7406\u5728\u5408\u9002\u7684\u65f6\u5019\u88ab\u8c03\u7528\u3002<\/p>\n<p>\u5f53\u542f\u52a8\u4e86 @AspectJ \u652f\u6301\u540e\uff0c\u53ea\u8981\u6211\u4eec\u5728 Spring \u5bb9\u5668\u4e2d\u914d\u7f6e\u4e00\u4e2a\u5e26 @Aspect \u6ce8\u91ca\u7684 Bean\uff0cSpring \u5c06\u4f1a\u81ea\u52a8\u8bc6\u522b\u8be5 Bean\uff0c\u5e76\u5c06\u8be5 Bean \u4f5c\u4e3a\u65b9\u9762 Bean \u5904\u7406\u3002<\/p>\n<p>\u5728 Spring \u5bb9\u5668\u4e2d\u914d\u7f6e\u65b9\u9762 Bean\uff08\u5373\u5e26 @Aspect \u6ce8\u91ca\u7684 Bean\uff09\uff0c\u4e0e\u914d\u7f6e\u666e\u901a Bean \u6ca1\u6709\u4efb\u4f55\u533a\u522b\uff0c\u4e00\u6837\u4f7f\u7528 &lt;bean\u2026\/&gt; \u5143\u7d20\u8fdb\u884c\u914d\u7f6e\uff0c\u4e00\u6837\u652f\u6301\u4f7f\u7528\u4f9d\u8d56\u6ce8\u5165\u6765\u914d\u7f6e\u5c5e\u6027\u503c\uff1b\u5982\u679c\u6211\u4eec\u542f\u52a8\u4e86 Spring \u7684\u201c\u96f6\u914d\u7f6e\u201d\u7279\u6027\uff0c\u4e00\u6837\u53ef\u4ee5\u8ba9 Spring \u81ea\u52a8\u641c\u7d22\uff0c\u5e76\u88c5\u8f7d\u6307\u5b9a\u8def\u5f84\u4e0b\u7684\u65b9\u9762 Bean\u3002<\/p>\n<p>\u4f7f\u7528 @Aspect \u6807\u6ce8\u4e00\u4e2a Java \u7c7b\uff0c\u8be5 Java \u7c7b\u5c06\u4f1a\u4f5c\u4e3a\u65b9\u9762 Bean\uff0c\u5982\u4e0b\u9762\u4ee3\u7801\u7247\u6bb5\u6240\u793a\uff1a<\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #666666; font-style: italic;\">\/\/ \u4f7f\u7528 @Aspect \u5b9a\u4e49\u4e00\u4e2a\u65b9\u9762\u7c7b<\/span><br \/>\n@Aspect<br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> LogAspect<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u8be5\u7c7b\u7684\u5176\u4ed6\u5185\u5bb9<\/span><br \/>\n...<br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u65b9\u9762\u7c7b\uff08\u7528 @Aspect \u4fee\u9970\u7684\u7c7b\uff09\u548c\u5176\u4ed6\u7c7b\u4e00\u6837\u53ef\u4ee5\u6709\u65b9\u6cd5\u3001\u5c5e\u6027\u5b9a\u4e49\uff0c\u8fd8\u53ef\u80fd\u5305\u62ec\u5207\u5165\u70b9\u3001\u589e\u5f3a\u5904\u7406\u5b9a\u4e49\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528 @Aspect \u6765\u4fee\u9970\u4e00\u4e2a Java \u7c7b\u4e4b\u540e\uff0cSpring \u5c06\u4e0d\u4f1a\u628a\u8be5 Bean \u5f53\u6210\u7ec4\u4ef6 Bean \u5904\u7406\uff0c\u56e0\u6b64\u8d1f\u8d23\u81ea\u52a8\u589e\u5f3a\u7684\u540e\u5904\u7406 Bean \u5c06\u4f1a\u7565\u8fc7\u8be5 Bean\uff0c\u4e0d\u4f1a\u5bf9\u8be5 Bean \u8fdb\u884c\u4efb\u4f55\u589e\u5f3a\u5904\u7406\u3002<\/p>\n<p>\u5f00\u53d1\u65f6\u65e0\u987b\u62c5\u5fc3\u4f7f\u7528 @Aspect \u5b9a\u4e49\u7684\u65b9\u9762\u7c7b\u88ab\u589e\u5f3a\u5904\u7406\uff0c\u5f53 Spring \u5bb9\u5668\u68c0\u6d4b\u5230\u67d0\u4e2a Bean \u7c7b\u4f7f\u7528\u4e86 @Aspect \u6807\u6ce8\u4e4b\u540e\uff0cSpring \u5bb9\u5668\u4e0d\u4f1a\u5bf9\u8be5 Bean \u7c7b\u8fdb\u884c\u589e\u5f3a\u3002<\/p>\n<p>\u4e0b\u9762\u5c06\u4f1a\u8003\u8651\u91c7\u7528 Spring AOP \u6765\u6539\u5199\u524d\u9762\u4ecb\u7ecd\u7684\u4f8b\u5b50\uff1a<\/p>\n<p>\u4e0b\u9762\u4f8b\u5b50\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684 Chinese \u7c7b\u6765\u6a21\u62df\u4e1a\u52a1\u903b\u8f91\u7ec4\u4ef6\uff1a<\/p>\n<p><strong>\u6e05\u5355 5.Chinese.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\">@<span style=\"color: #003399;\">Component<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> Chinese<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9e\u73b0 Person \u63a5\u53e3\u7684 sayHello() \u65b9\u6cd5<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #003399;\">String<\/span> sayHello<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span> name<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;-- \u6b63\u5728\u6267\u884c sayHello \u65b9\u6cd5 --&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u8fd4\u56de\u7b80\u5355\u7684\u5b57\u7b26\u4e32<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">return<\/span> name <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000ff;\">&quot; Hello , Spring AOP&quot;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u4e00\u4e2a eat() \u65b9\u6cd5<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> eat<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span> food<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6211\u6b63\u5728\u5403 :&quot;<\/span><span style=\"color: #339933;\">+<\/span> food<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u63d0\u4f9b\u4e86\u4e0a\u9762 Chinese \u7c7b\u4e4b\u540e\uff0c\u63a5\u4e0b\u6765\u5047\u8bbe\u540c\u6837\u9700\u8981\u4e3a\u4e0a\u9762 Chinese \u7c7b\u7684\u6bcf\u4e2a\u65b9\u6cd5\u589e\u52a0\u4e8b\u52a1\u63a7\u5236\u3001\u65e5\u5fd7\u8bb0\u5f55\uff0c\u6b64\u65f6\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 Around\u3001AfterReturning \u4e24\u79cd\u589e\u5f3a\u5904\u7406\u3002<\/p>\n<p>\u5148\u770b AfterReturning \u589e\u5f3a\u5904\u7406\u4ee3\u7801\u3002<\/p>\n<p><strong>\u6e05\u5355 6.AfterReturningAdviceTest.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u65b9\u9762<\/span><br \/>\n@Aspect<br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> AfterReturningAdviceTest<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5339\u914d org.crazyit.app.service.impl \u5305\u4e0b\u6240\u6709\u7c7b\u7684\u3001<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u6240\u6709\u65b9\u6cd5\u7684\u6267\u884c\u4f5c\u4e3a\u5207\u5165\u70b9<\/span><br \/>\n@AfterReturning<span style=\"color: #009900;\">&#40;<\/span>returning<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000ff;\">&quot;rvt&quot;<\/span>, pointcut<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000ff;\">&quot;execution(* org.crazyit.app.service.impl.*.*(..))&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> log<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">Object<\/span> rvt<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u83b7\u53d6\u76ee\u6807\u65b9\u6cd5\u8fd4\u56de\u503c :&quot;<\/span> <span style=\"color: #339933;\">+<\/span> rvt<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6a21\u62df\u8bb0\u5f55\u65e5\u5fd7\u529f\u80fd ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762 Aspect \u7c7b\u4f7f\u7528\u4e86 @Aspect \u4fee\u9970\uff0c\u8fd9\u6837 Spring \u4f1a\u5c06\u5b83\u5f53\u6210\u4e00\u4e2a\u65b9\u9762 Bean \u8fdb\u884c\u5904\u7406\u3002\u5176\u4e2d\u7a0b\u5e8f\u4e2d\u7c97\u4f53\u5b57\u4ee3\u7801\u6307\u5b9a\u5c06\u4f1a\u5728\u8c03\u7528 org.crazyit.app.service.impl \u5305\u4e0b\u7684\u6240\u6709\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\u4e4b\u540e\u7ec7\u5165 log(Object rvt) \u65b9\u6cd5\u3002<\/p>\n<p>\u518d\u770b Around \u589e\u5f3a\u5904\u7406\u4ee3\u7801\uff1a<\/p>\n<p><strong>\u6e05\u5355 7.AfterReturningAdviceTest.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #666666; font-style: italic;\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u65b9\u9762<\/span><br \/>\n@Aspect<br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> AroundAdviceTest<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u5339\u914d org.crazyit.app.service.impl \u5305\u4e0b\u6240\u6709\u7c7b\u7684\u3001<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u6240\u6709\u65b9\u6cd5\u7684\u6267\u884c\u4f5c\u4e3a\u5207\u5165\u70b9<\/span><br \/>\n@Around<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;execution(* org.crazyit.app.service.impl.*.*(..))&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #003399;\">Object<\/span> processTx<span style=\"color: #009900;\">&#40;<\/span>ProceedingJoinPoint jp<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">throws<\/span> java.<span style=\"color: #006633;\">lang<\/span>.<span style=\"color: #003399;\">Throwable<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u6267\u884c\u76ee\u6807\u65b9\u6cd5\uff0c\u5e76\u4fdd\u5b58\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c<\/span><br \/>\n<span style=\"color: #003399;\">Object<\/span> rvt <span style=\"color: #339933;\">=<\/span> jp.<span style=\"color: #006633;\">proceed<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span><span style=\"color: #009900;\">&#123;<\/span><span style=\"color: #0000ff;\">&quot;\u88ab\u6539\u53d8\u7684\u53c2\u6570&quot;<\/span><span style=\"color: #009900;\">&#125;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">return<\/span> rvt <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000ff;\">&quot; \u65b0\u589e\u7684\u5185\u5bb9&quot;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0e\u524d\u9762\u7684 AfterReturning \u589e\u5f3a\u5904\u7406\u7c7b\u4f3c\u7684\uff0c\u6b64\u5904\u540c\u6837\u4f7f\u7528\u4e86 @Aspect \u6765\u4fee\u9970\u524d\u9762 Bean\uff0c\u5176\u4e2d\u7c97\u4f53\u5b57\u4ee3\u7801\u6307\u5b9a\u5728\u8c03\u7528 org.crazyit.app.service.impl \u5305\u4e0b\u7684\u6240\u6709\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\u7684\u201c\u524d\u540e\uff08Around\uff09\u201d \u7ec7\u5165 processTx(ProceedingJoinPoint jp) \u65b9\u6cd5<\/p>\n<p>\u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u867d\u7136\u6b64\u5904\u53ea\u4ecb\u7ecd\u4e86 Spring AOP \u7684 AfterReturning\u3001Around \u4e24\u79cd\u589e\u5f3a\u5904\u7406\uff0c\u4f46\u5b9e\u9645\u4e0a Spring \u8fd8\u652f\u6301 Before\u3001After\u3001AfterThrowing \u7b49\u589e\u5f3a\u5904\u7406\uff0c\u5173\u4e8e Spring AOP \u7f16\u7a0b\u66f4\u591a\u3001\u66f4\u7ec6\u81f4\u7684\u7f16\u7a0b\u7ec6\u8282\uff0c\u53ef\u4ee5\u53c2\u8003\u300a\u8f7b\u91cf\u7ea7 Java EE \u4f01\u4e1a\u5e94\u7528\u5b9e\u6218\u300b\u4e00\u4e66\u3002<\/p>\n<p>\u672c\u793a\u4f8b\u91c7\u7528\u4e86 Spring \u7684\u96f6\u914d\u7f6e\u6765\u5f00\u542f Spring AOP\uff0c\u56e0\u6b64\u4e0a\u9762 Chinese \u7c7b\u4f7f\u7528\u4e86 @Component \u4fee\u9970\uff0c\u800c\u65b9\u9762 Bean \u5219\u4f7f\u7528\u4e86 @Aspect \u4fee\u9970\uff0c\u65b9\u9762 Bean \u4e2d\u7684 Advice \u5219\u5206\u522b\u4f7f\u7528\u4e86 @AfterReturning\u3001@Around \u4fee\u9970\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6309\u4f20\u7edf\u65b9\u5f0f\u6765\u83b7\u53d6 Spring \u5bb9\u5668\u4e2d chinese Bean\u3001\u5e76\u8c03\u7528\u8be5 Bean \u7684\u4e24\u4e2a\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u6e05\u5355 9.BeanTest.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> BeanTest<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> args<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u521b\u5efa Spring \u5bb9\u5668<\/span><br \/>\nApplicationContext ctx <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span><br \/>\nClassPathXmlApplicationContext<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;bean.xml&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nChinese p <span style=\"color: #339933;\">=<\/span> ctx.<span style=\"color: #006633;\">getBean<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;chinese&quot;<\/span> ,Chinese.<span style=\"color: #000000; font-weight: bold;\">class<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span>p.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u5f20\u4e09&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\np.<span style=\"color: #006633;\">eat<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u897f\u74dc&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4ece\u4e0a\u9762\u5f00\u53d1\u8fc7\u7a0b\u53ef\u4ee5\u770b\u51fa\uff0c\u5bf9\u4e8e Spring AOP \u800c\u8a00\uff0c\u5f00\u53d1\u8005\u63d0\u4f9b\u7684\u4e1a\u52a1\u7ec4\u4ef6\u3001\u65b9\u9762 Bean \u5e76\u6ca1\u6709\u4efb\u4f55\u7279\u522b\u7684\u5730\u65b9\u3002\u53ea\u662f\u65b9\u9762 Bean \u9700\u8981\u4f7f\u7528 @Aspect \u4fee\u9970\u5373\u53ef\u3002\u7a0b\u5e8f\u4e0d\u9700\u8981\u4f7f\u7528\u7279\u522b\u7684\u7f16\u8bd1\u5668\u3001\u7ec7\u5165\u5668\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u8fd0\u884c\u4e0a\u9762\u7a0b\u5e8f\uff0c\u5c06\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>\u2013 \u6b63\u5728\u6267\u884c sayHello \u65b9\u6cd5 \u2013<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 \u2026<\/p>\n<p>\u83b7\u53d6\u76ee\u6807\u65b9\u6cd5\u8fd4\u56de\u503c : \u88ab\u6539\u53d8\u7684\u53c2\u6570 Hello , Spring AOP \u65b0\u589e\u7684\u5185\u5bb9<\/p>\n<p>\u6a21\u62df\u8bb0\u5f55\u65e5\u5fd7\u529f\u80fd \u2026<\/p>\n<p>\u88ab\u6539\u53d8\u7684\u53c2\u6570 Hello , Spring AOP \u65b0\u589e\u7684\u5185\u5bb9<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>\u6211\u6b63\u5728\u5403 : \u88ab\u6539\u53d8\u7684\u53c2\u6570<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 \u2026<\/p>\n<p>\u83b7\u53d6\u76ee\u6807\u65b9\u6cd5\u8fd4\u56de\u503c :null \u65b0\u589e\u7684\u5185\u5bb9<\/p>\n<p>\u6a21\u62df\u8bb0\u5f55\u65e5\u5fd7\u529f\u80fd \u2026<\/p>\n<p>\u867d\u7136\u7a0b\u5e8f\u662f\u5728\u8c03\u7528 Chinese \u5bf9\u8c61\u7684 sayHello\u3001eat \u4e24\u4e2a\u65b9\u6cd5\uff0c\u4f46\u4ece\u4e0a\u9762\u8fd0\u884c\u7ed3\u679c\u4e0d\u96be\u770b\u51fa\uff1a\u5b9e\u9645\u6267\u884c\u7684\u7edd\u5bf9\u4e0d\u662f Chinese \u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u800c\u662f AOP \u4ee3\u7406\u7684\u65b9\u6cd5\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cSpring AOP \u540c\u6837\u4e3a Chinese \u7c7b\u751f\u6210\u4e86 AOP \u4ee3\u7406\u7c7b\u3002\u8fd9\u4e00\u70b9\u53ef\u901a\u8fc7\u5728\u7a0b\u5e8f\u4e2d\u589e\u52a0\u5982\u4e0b\u4ee3\u7801\u770b\u51fa\uff1a<\/p>\n<p>System.out.println(p.getClass());<\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u53ef\u4ee5\u8f93\u51fa p \u53d8\u91cf\u6240\u5f15\u7528\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\uff0c\u518d\u6b21\u6267\u884c\u7a0b\u5e8f\u5c06\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u4ee3\u7801\u4ea7\u751f class org.crazyit.app.service.impl.ChineseEnhancerByCGLIB290441d2 \u7684\u8f93\u51fa\uff0c\u8fd9\u624d\u662f p \u53d8\u91cf\u6240\u5f15\u7528\u7684\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\uff0c\u8fd9\u4e2a\u7c7b\u4e5f\u5c31\u662f Spring AOP \u52a8\u6001\u751f\u6210\u7684 AOP \u4ee3\u7406\u7c7b\u3002\u4ece AOP \u4ee3\u7406\u7c7b\u7684\u7c7b\u540d\u53ef\u4ee5\u770b\u51fa\uff0cAOP \u4ee3\u7406\u7c7b\u662f\u7531 CGLIB \u6765\u751f\u6210\u7684\u3002<\/p>\n<p>\u5982\u679c\u5c06\u4e0a\u9762\u7a0b\u5e8f\u7a0b\u5e8f\u7a0d\u4f5c\u4fee\u6539\uff1a\u53ea\u8981\u8ba9\u4e0a\u9762\u4e1a\u52a1\u903b\u8f91\u7c7b Chinese \u7c7b\u5b9e\u73b0\u4e00\u4e2a\u4efb\u610f\u63a5\u53e3\u2014\u2014\u8fd9\u79cd\u505a\u6cd5\u66f4\u7b26\u5408 Spring \u6240\u5021\u5bfc\u7684\u201c\u9762\u5411\u63a5\u53e3\u7f16\u7a0b\u201d\u7684\u539f\u5219\u3002\u5047\u8bbe\u7a0b\u5e8f\u4e3a Chinese \u7c7b\u63d0\u4f9b\u5982\u4e0b Person \u63a5\u53e3\uff0c\u5e76\u8ba9 Chinese \u7c7b\u5b9e\u73b0\u8be5\u63a5\u53e3\uff1a<\/p>\n<p><strong>\u6e05\u5355 10.Person.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">interface<\/span> Person<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">String<\/span> sayHello<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span> name<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #000066; font-weight: bold;\">void<\/span> eat<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span> food<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u63a5\u4e0b\u6765\u8ba9 BeanTest \u7c7b\u9762\u5411 Person \u63a5\u53e3\u3001\u800c\u4e0d\u662f Chinese \u7c7b\u7f16\u7a0b\u3002\u5373\u5c06 BeanTest \u7c7b\u6539\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff1a<\/p>\n<p><strong>\u6e05\u5355 11.BeanTest.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> BeanTest<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> args<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u521b\u5efa Spring \u5bb9\u5668<\/span><br \/>\nApplicationContext ctx <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span><br \/>\nClassPathXmlApplicationContext<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;bean.xml&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nPerson p <span style=\"color: #339933;\">=<\/span> ctx.<span style=\"color: #006633;\">getBean<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;chinese&quot;<\/span> ,Person.<span style=\"color: #000000; font-weight: bold;\">class<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span>p.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u5f20\u4e09&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\np.<span style=\"color: #006633;\">eat<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u897f\u74dc&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span>p.<span style=\"color: #006633;\">getClass<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u539f\u6765\u7684\u7a0b\u5e8f\u662f\u5c06\u9762\u5411 Chinese \u7c7b\u7f16\u7a0b\uff0c\u73b0\u5728\u5c06\u8be5\u7a0b\u5e8f\u6539\u4e3a\u9762\u5411 Person \u63a5\u53e3\u7f16\u7a0b\uff0c\u518d\u6b21\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u6ca1\u6709\u53d1\u751f\u6539\u53d8\u3002\u53ea\u662f System.out.println(p.getClass()); \u5c06\u4f1a\u8f93\u51fa class $Proxy7\uff0c\u8fd9\u8bf4\u660e\u6b64\u65f6\u7684 AOP \u4ee3\u7406\u5e76\u4e0d\u662f\u7531 CGLIB \u751f\u6210\u7684\uff0c\u800c\u662f\u7531 JDK \u52a8\u6001\u4ee3\u7406\u751f\u6210\u7684\u3002<\/p>\n<p>Spring AOP \u6846\u67b6\u5bf9 AOP \u4ee3\u7406\u7c7b\u7684\u5904\u7406\u539f\u5219\u662f\uff1a\u5982\u679c\u76ee\u6807\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\u5b9e\u73b0\u4e86\u63a5\u53e3\uff0cSpring AOP \u5c06\u4f1a\u91c7\u7528 JDK \u52a8\u6001\u4ee3\u7406\u6765\u751f\u6210 AOP \u4ee3\u7406\u7c7b\uff1b\u5982\u679c\u76ee\u6807\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\u6ca1\u6709\u5b9e\u73b0\u63a5\u53e3\uff0cSpring AOP \u5c06\u4f1a\u91c7\u7528 CGLIB \u6765\u751f\u6210 AOP \u4ee3\u7406\u7c7b\u2014\u2014\u4e0d\u8fc7\u8fd9\u4e2a\u9009\u62e9\u8fc7\u7a0b\u5bf9\u5f00\u53d1\u8005\u5b8c\u5168\u900f\u660e\u3001\u5f00\u53d1\u8005\u4e5f\u65e0\u9700\u5173\u5fc3\u3002<\/p>\n<p>Spring AOP \u4f1a\u52a8\u6001\u9009\u62e9\u4f7f\u7528 JDK \u52a8\u6001\u4ee3\u7406\u3001CGLIB \u6765\u751f\u6210 AOP \u4ee3\u7406\uff0c\u5982\u679c\u76ee\u6807\u7c7b\u5b9e\u73b0\u4e86\u63a5\u53e3\uff0cSpring AOP \u5219\u65e0\u9700 CGLIB \u7684\u652f\u6301\uff0c\u76f4\u63a5\u4f7f\u7528 JDK \u63d0\u4f9b\u7684 Proxy \u548c InvocationHandler \u6765\u751f\u6210 AOP \u4ee3\u7406\u5373\u53ef\u3002\u5173\u4e8e\u5982\u4f55 Proxy \u548c InvocationHandler \u6765\u751f\u6210\u52a8\u6001\u4ee3\u7406\u4e0d\u5728\u672c\u6587\u4ecb\u7ecd\u8303\u56f4\u4e4b\u5185\uff0c\u5982\u679c\u8bfb\u8005\u5bf9 Proxy \u548c InvocationHandler \u7684\u7528\u6cd5\u611f\u5174\u8da3\u5219\u53ef\u81ea\u884c\u53c2\u8003 Java API \u6587\u6863\u6216\u300a\u75af\u72c2 Java \u8bb2\u4e49\u300b\u3002<\/p>\n<p><strong>Spring AOP \u539f\u7406\u5256\u6790<\/strong><\/p>\n<p>\u901a\u8fc7\u524d\u9762\u4ecb\u7ecd\u53ef\u4ee5\u77e5\u9053\uff1aAOP \u4ee3\u7406\u5176\u5b9e\u662f\u7531 AOP \u6846\u67b6\u52a8\u6001\u751f\u6210\u7684\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u53ef\u4f5c\u4e3a\u76ee\u6807\u5bf9\u8c61\u4f7f\u7528\u3002AOP \u4ee3\u7406\u5305\u542b\u4e86\u76ee\u6807\u5bf9\u8c61\u7684\u5168\u90e8\u65b9\u6cd5\uff0c\u4f46 AOP \u4ee3\u7406\u4e2d\u7684\u65b9\u6cd5\u4e0e\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5\u5b58\u5728\u5dee\u5f02\uff1aAOP \u65b9\u6cd5\u5728\u7279\u5b9a\u5207\u5165\u70b9\u6dfb\u52a0\u4e86\u589e\u5f3a\u5904\u7406\uff0c\u5e76\u56de\u8c03\u4e86\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002<\/p>\n<p>AOP \u4ee3\u7406\u6240\u5305\u542b\u7684\u65b9\u6cd5\u4e0e\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5\u793a\u610f\u56fe\u5982\u56fe 3 \u6240\u793a\u3002<\/p>\n<p style=\"text-align: center;\"><strong>\u56fe 3.AOP \u4ee3\u7406\u7684\u65b9\u6cd5\u4e0e\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5<\/strong><br \/>\n<a href=\"http:\/\/weitaoc.com\/?attachment_id=275\" rel=\"attachment wp-att-262\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-262\" src=\"http:\/\/weitaoc.com\/wp-content\/uploads\/2015\/05\/1.gif\" alt=\"1\" width=\"300\" height=\"246\" \/><\/a><br \/>\nSpring \u7684 AOP \u4ee3\u7406\u7531 Spring \u7684 IoC \u5bb9\u5668\u8d1f\u8d23\u751f\u6210\u3001\u7ba1\u7406\uff0c\u5176\u4f9d\u8d56\u5173\u7cfb\u4e5f\u7531 IoC \u5bb9\u5668\u8d1f\u8d23\u7ba1\u7406\u3002\u56e0\u6b64\uff0cAOP \u4ee3\u7406\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5bb9\u5668\u4e2d\u7684\u5176\u4ed6 Bean \u5b9e\u4f8b\u4f5c\u4e3a\u76ee\u6807\uff0c\u8fd9\u79cd\u5173\u7cfb\u53ef\u7531 IoC \u5bb9\u5668\u7684\u4f9d\u8d56\u6ce8\u5165\u63d0\u4f9b\u3002<\/p>\n<p>\u7eb5\u89c2 AOP \u7f16\u7a0b\uff0c\u5176\u4e2d\u9700\u8981\u7a0b\u5e8f\u5458\u53c2\u4e0e\u7684\u53ea\u6709 3 \u4e2a\u90e8\u5206\uff1a<\/p>\n<p>\u25cf \u5b9a\u4e49\u666e\u901a\u4e1a\u52a1\u7ec4\u4ef6\u3002<\/p>\n<p>\u25cf\u00a0\u5b9a\u4e49\u5207\u5165\u70b9\uff0c\u4e00\u4e2a\u5207\u5165\u70b9\u53ef\u80fd\u6a2a\u5207\u591a\u4e2a\u4e1a\u52a1\u7ec4\u4ef6\u3002<\/p>\n<p>\u25cf\u00a0\u5b9a\u4e49\u589e\u5f3a\u5904\u7406\uff0c\u589e\u5f3a\u5904\u7406\u5c31\u662f\u5728 AOP \u6846\u67b6\u4e3a\u666e\u901a\u4e1a\u52a1\u7ec4\u4ef6\u7ec7\u5165\u7684\u5904\u7406\u52a8\u4f5c\u3002<\/p>\n<p>\u4e0a\u9762 3 \u4e2a\u90e8\u5206\u7684\u7b2c\u4e00\u4e2a\u90e8\u5206\u662f\u6700\u5e73\u5e38\u4e0d\u8fc7\u7684\u4e8b\u60c5\uff0c\u65e0\u987b\u989d\u5916\u8bf4\u660e\u3002\u90a3\u4e48\u8fdb\u884c AOP \u7f16\u7a0b\u7684\u5173\u952e\u5c31\u662f\u5b9a\u4e49\u5207\u5165\u70b9\u548c\u5b9a\u4e49\u589e\u5f3a\u5904\u7406\u3002\u4e00\u65e6\u5b9a\u4e49\u4e86\u5408\u9002\u7684\u5207\u5165\u70b9\u548c\u589e\u5f3a\u5904\u7406\uff0cAOP \u6846\u67b6\u5c06\u4f1a\u81ea\u52a8\u751f\u6210 AOP \u4ee3\u7406\uff0c\u800c AOP \u4ee3\u7406\u7684\u65b9\u6cd5\u5927\u81f4\u6709\u5982\u4e0b\u516c\u5f0f\uff1a<\/p>\n<p><strong>\u4ee3\u7406\u5bf9\u8c61\u7684\u65b9\u6cd5 = \u589e\u5f3a\u5904\u7406 + \u88ab\u4ee3\u7406\u5bf9\u8c61\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728\u4e0a\u9762\u8fd9\u4e2a\u4e1a\u52a1\u5b9a\u4e49\u4e2d\uff0c\u4e0d\u96be\u53d1\u73b0 Spring AOP \u7684\u5b9e\u73b0\u539f\u7406\u5176\u5b9e\u5f88\u7b80\u5355\uff1aAOP \u6846\u67b6\u8d1f\u8d23\u52a8\u6001\u5730\u751f\u6210 AOP \u4ee3\u7406\u7c7b\uff0c\u8fd9\u4e2a\u4ee3\u7406\u7c7b\u7684\u65b9\u6cd5\u5219\u7531 Advice \u548c\u56de\u8c03\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5\u6240\u7ec4\u6210\u3002<\/p>\n<p>\u5bf9\u4e8e\u524d\u9762\u63d0\u5230\u7684\u56fe 2 \u6240\u793a\u7684\u8f6f\u4ef6\u8c03\u7528\u7ed3\u6784\uff1a\u5f53\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u2026\u2026\u90fd\u9700\u8981\u53bb\u8c03\u7528\u67d0\u4e2a\u5177\u6709\u201c\u6a2a\u5207\u201d\u6027\u8d28\u7684\u65b9\u6cd5\u65f6\uff0c\u4f20\u7edf\u7684\u505a\u6cd5\u662f\u7a0b\u5e8f\u5458\u53bb\u624b\u52a8\u4fee\u6539\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u2026\u2026\u3001\u901a\u8fc7\u4ee3\u7801\u6765\u8c03\u7528\u8fd9\u4e2a\u5177\u6709\u201c\u6a2a\u5207\u201d\u6027\u8d28\u7684\u65b9\u6cd5\uff0c\u4f46\u8fd9\u79cd\u505a\u6cd5\u7684\u53ef\u6269\u5c55\u6027\u4e0d\u597d\uff0c\u56e0\u4e3a\u6bcf\u6b21\u90fd\u8981\u6539\u4ee3\u7801\u3002<\/p>\n<p>\u4e8e\u662f AOP \u6846\u67b6\u51fa\u73b0\u4e86\uff0cAOP \u6846\u67b6\u5219\u53ef\u4ee5\u201c\u52a8\u6001\u7684\u201d\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u4ee3\u7406\u7c7b\uff0c\u800c\u8fd9\u4e2a\u4ee3\u7406\u7c7b\u6240\u5305\u542b\u7684\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u2026\u2026\u4e5f\u589e\u52a0\u4e86\u8c03\u7528\u8fd9\u4e2a\u5177\u6709\u201c\u6a2a\u5207\u201d\u6027\u8d28\u7684\u65b9\u6cd5\u2014\u2014\u4f46\u8fd9\u79cd\u8c03\u7528\u7531 AOP \u6846\u67b6\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7406\u7c7b\u6765\u8d1f\u8d23\uff0c\u56e0\u6b64\u5177\u6709\u4e86\u6781\u597d\u7684\u6269\u5c55\u6027\u3002\u7a0b\u5e8f\u5458\u65e0\u9700\u624b\u52a8\u4fee\u6539\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u7684\u4ee3\u7801\uff0c\u7a0b\u5e8f\u5458\u53ea\u8981\u5b9a\u4e49\u5207\u5165\u70b9\u5373\u53ef\u2014\u2014 AOP \u6846\u67b6\u6240\u751f\u6210\u7684 AOP \u4ee3\u7406\u7c7b\u4e2d\u5305\u542b\u4e86\u65b0\u7684\u65b9\u6cd5 1\u3001\u8bbf\u6cd5 2\u3001\u65b9\u6cd5 3\uff0c\u800c AOP \u6846\u67b6\u4f1a\u6839\u636e\u5207\u5165\u70b9\u6765\u51b3\u5b9a\u662f\u5426\u8981\u5728\u65b9\u6cd5 1\u3001\u65b9\u6cd5 2\u3001\u65b9\u6cd5 3 \u4e2d\u56de\u8c03\u5177\u6709\u201c\u6a2a\u5207\u201d\u6027\u8d28\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u7b80\u800c\u8a00\u4e4b\uff1aAOP \u539f\u7406\u7684\u5965\u5999\u5c31\u5728\u4e8e\u52a8\u6001\u5730\u751f\u6210\u4e86\u4ee3\u7406\u7c7b\uff0c\u8fd9\u4e2a\u4ee3\u7406\u7c7b\u5b9e\u73b0\u4e86\u56fe 2 \u7684\u8c03\u7528\u2014\u2014\u8fd9\u79cd\u8c03\u7528\u65e0\u9700\u7a0b\u5e8f\u5458\u4fee\u6539\u4ee3\u7801\u3002\u63a5\u4e0b\u6765\u4ecb\u7ecd\u7684 CGLIB \u5c31\u662f\u4e00\u4e2a\u4ee3\u7406\u751f\u6210\u5e93\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 CGLIB \u6765\u751f\u6210\u4ee3\u7406\u7c7b\u3002<\/p>\n<p><strong>\u4f7f\u7528 CGLIB \u751f\u6210\u4ee3\u7406\u7c7b<\/strong><\/p>\n<p>CGLIB\uff08Code Generation Library\uff09\uff0c\u7b80\u5355\u6765\u8bf4\uff0c\u5c31\u662f\u4e00\u4e2a\u4ee3\u7801\u751f\u6210\u7c7b\u5e93\u3002\u5b83\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u5019\u52a8\u6001\u662f\u751f\u6210\u67d0\u4e2a\u7c7b\u7684\u5b50\u7c7b\u3002<\/p>\n<p>\u6b64\u5904\u4f7f\u7528\u524d\u9762\u5b9a\u4e49\u7684 Chinese \u7c7b\uff0c\u73b0\u5728\u6539\u4e3a\u76f4\u63a5\u4f7f\u7528 CGLIB \u6765\u751f\u6210\u4ee3\u7406\uff0c\u8fd9\u4e2a\u4ee3\u7406\u7c7b\u540c\u6837\u53ef\u4ee5\u5b9e\u73b0 Spring AOP \u4ee3\u7406\u6240\u8fbe\u5230\u7684\u6548\u679c\u3002<\/p>\n<p>\u4e0b\u9762\u5148\u4e3a CGLIB \u63d0\u4f9b\u4e00\u4e2a\u62e6\u622a\u5668\u5b9e\u73b0\u7c7b\uff1a<\/p>\n<p><strong>\u6e05\u5355 12.AroundAdvice.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> AroundAdvice <span style=\"color: #000000; font-weight: bold;\">implements<\/span> MethodInterceptor<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #003399;\">Object<\/span> intercept<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">Object<\/span> target, <span style=\"color: #003399;\">Method<\/span> method<br \/>\n, <span style=\"color: #003399;\">Object<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> args, MethodProxy proxy<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">throws<\/span> java.<span style=\"color: #006633;\">lang<\/span>.<span style=\"color: #003399;\">Throwable<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u6267\u884c\u76ee\u6807\u65b9\u6cd5\uff0c\u5e76\u4fdd\u5b58\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c<\/span><br \/>\n<span style=\"color: #003399;\">Object<\/span> rvt <span style=\"color: #339933;\">=<\/span> proxy.<span style=\"color: #006633;\">invokeSuper<\/span><span style=\"color: #009900;\">&#40;<\/span>target, <span style=\"color: #000000; font-weight: bold;\">new<\/span> <span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span><span style=\"color: #009900;\">&#123;<\/span><span style=\"color: #0000ff;\">&quot;\u88ab\u6539\u53d8\u7684\u53c2\u6570&quot;<\/span><span style=\"color: #009900;\">&#125;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 ...&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">return<\/span> rvt <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000ff;\">&quot; \u65b0\u589e\u7684\u5185\u5bb9&quot;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762\u8fd9\u4e2a AroundAdvice.java \u7684\u4f5c\u7528\u5c31\u50cf\u524d\u9762\u4ecb\u7ecd\u7684 Around Advice\uff0c\u5b83\u53ef\u4ee5\u5728\u8c03\u7528\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\u3001\u8c03\u7528\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\u7ec7\u5165\u589e\u5f3a\u5904\u7406\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u7a0b\u5e8f\u63d0\u4f9b\u4e00\u4e2a ChineseProxyFactory \u7c7b\uff0c\u8fd9\u4e2a ChineseProxyFactory \u7c7b\u4f1a\u901a\u8fc7 CGLIB \u6765\u4e3a Chinese \u751f\u6210\u4ee3\u7406\u7c7b\uff1a<\/p>\n<p><strong>\u6e05\u5355 13.ChineseProxyFactory.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> ChineseProxyFactory<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> Chinese getAuthInstance<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\nEnhancer en <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000000; font-weight: bold;\">new<\/span> Enhancer<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u8bbe\u7f6e\u8981\u4ee3\u7406\u7684\u76ee\u6807\u7c7b<\/span><br \/>\nen.<span style=\"color: #006633;\">setSuperclass<\/span><span style=\"color: #009900;\">&#40;<\/span>Chinese.<span style=\"color: #000000; font-weight: bold;\">class<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u8bbe\u7f6e\u8981\u4ee3\u7406\u7684\u62e6\u622a\u5668<\/span><br \/>\nen.<span style=\"color: #006633;\">setCallback<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #000000; font-weight: bold;\">new<\/span> AroundAdvice<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #666666; font-style: italic;\">\/\/ \u751f\u6210\u4ee3\u7406\u7c7b\u7684\u5b9e\u4f8b<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">return<\/span> <span style=\"color: #009900;\">&#40;<\/span>Chinese<span style=\"color: #009900;\">&#41;<\/span>en.<span style=\"color: #006633;\">create<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u4e0a\u9762\u7c97\u4f53\u5b57\u4ee3\u7801\u5c31\u662f\u4f7f\u7528 CGLIB \u7684 Enhancer \u751f\u6210\u4ee3\u7406\u5bf9\u8c61\u7684\u5173\u952e\u4ee3\u7801\uff0c\u6b64\u65f6\u7684 Enhancer \u5c06\u4ee5 Chinese \u7c7b\u4f5c\u4e3a\u76ee\u6807\u7c7b\uff0c\u4ee5 AroundAdvice \u5bf9\u8c61\u4f5c\u4e3a\u201cAdvice\u201d\uff0c\u7a0b\u5e8f\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a Chinese \u7684\u5b50\u7c7b\uff0c\u8fd9\u4e2a\u5b50\u7c7b\u5c31\u662f CGLIB \u751f\u6210\u4ee3\u7406\u7c7b\uff0c\u5b83\u53ef\u4f5c\u4e3a Chinese \u5bf9\u8c61\u4f7f\u7528\uff0c\u4f46\u5b83\u589e\u5f3a\u4e86 Chinese \u7c7b\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u6d4b\u8bd5 Chinese \u4ee3\u7406\u7c7b\u7684\u4e3b\u7a0b\u5e8f\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u6e05\u5355 14.Main.java<\/strong><\/p>\n<div class=\"codecolorer-container java geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/><\/div><\/td><td><div class=\"java codecolorer\" style=\"white-space:nowrap\"><span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">class<\/span> Main<br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">static<\/span> <span style=\"color: #000066; font-weight: bold;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #003399;\">String<\/span><span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> args<span style=\"color: #009900;\">&#41;<\/span><br \/>\n<span style=\"color: #009900;\">&#123;<\/span><br \/>\nChinese chin <span style=\"color: #339933;\">=<\/span> ChineseProxyFactory.<span style=\"color: #006633;\">getAuthInstance<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span>chin.<span style=\"color: #006633;\">sayHello<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u5b59\u609f\u7a7a&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\nchin.<span style=\"color: #006633;\">eat<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000ff;\">&quot;\u897f\u74dc&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #003399;\">System<\/span>.<span style=\"color: #006633;\">out<\/span>.<span style=\"color: #006633;\">println<\/span><span style=\"color: #009900;\">&#40;<\/span>chin.<span style=\"color: #006633;\">getClass<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><br \/>\n<span style=\"color: #009900;\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u8fd0\u884c\u4e0a\u9762\u4e3b\u7a0b\u5e8f\uff0c\u770b\u5230\u5982\u4e0b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>\u2013 \u6b63\u5728\u6267\u884c sayHello \u65b9\u6cd5 \u2013<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 \u2026<\/p>\n<p>\u88ab\u6539\u53d8\u7684\u53c2\u6570 Hello , CGLIB \u65b0\u589e\u7684\u5185\u5bb9<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u524d\uff0c\u6a21\u62df\u5f00\u59cb\u4e8b\u52a1 \u2026<\/p>\n<p>\u6211\u6b63\u5728\u5403 : \u88ab\u6539\u53d8\u7684\u53c2\u6570<\/p>\n<p>\u6267\u884c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\uff0c\u6a21\u62df\u7ed3\u675f\u4e8b\u52a1 \u2026<\/p>\n<p>class lee.ChineseEnhancerByCGLIB4bd097d9<\/p>\n<p>\u4ece\u4e0a\u9762\u8f93\u51fa\u7ed3\u679c\u6765\u770b\uff0cCGLIB \u751f\u6210\u7684\u4ee3\u7406\u5b8c\u5168\u53ef\u4ee5\u4f5c\u4e3a Chinese \u5bf9\u8c61\u6765\u4f7f\u7528\uff0c\u800c\u4e14 CGLIB \u4ee3\u7406\u5bf9\u8c61\u7684 sayHello()\u3001eat() \u4e24\u4e2a\u65b9\u6cd5\u5df2\u7ecf\u589e\u52a0\u4e86\u4e8b\u52a1\u63a7\u5236\uff08\u53ea\u662f\u6a21\u62df\uff09\uff0c\u8fd9\u4e2a CGLIB \u4ee3\u7406\u5176\u5b9e\u5c31\u662f Spring AOP \u6240\u751f\u6210\u7684 AOP \u4ee3\u7406\u3002<\/p>\n<p>\u901a\u8fc7\u7a0b\u5e8f\u6700\u540e\u7684\u8f93\u51fa\uff0c\u4e0d\u96be\u53d1\u73b0\u8fd9\u4e2a\u4ee3\u7406\u5bf9\u8c61\u7684\u5b9e\u73b0\u7c7b\u662f lee.ChineseEnhancerByCGLIB4bd097d9\uff0c\u8fd9\u5c31\u662f CGLIB \u6240\u751f\u6210\u7684\u4ee3\u7406\u7c7b\uff0c\u8fd9\u4e2a\u4ee3\u7406\u7c7b\u7684\u683c\u5f0f\u4e0e\u524d\u9762 Spring AOP \u6240\u751f\u6210\u7684\u4ee3\u7406\u7c7b\u7684\u683c\u5f0f\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n<p>\u8fd9\u5c31\u662f Spring AOP \u7684\u6839\u672c\u6240\u5728\uff1aSpring AOP \u5c31\u662f\u901a\u8fc7 CGLIB \u6765\u52a8\u6001\u5730\u751f\u6210\u4ee3\u7406\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u4ee3\u7406\u5bf9\u8c61\u5c31\u662f\u6240\u8c13\u7684 AOP \u4ee3\u7406\uff0c\u800c AOP \u4ee3\u7406\u7684\u65b9\u6cd5\u5219\u901a\u8fc7\u5728\u76ee\u6807\u5bf9\u8c61\u7684\u5207\u5165\u70b9\u52a8\u6001\u5730\u7ec7\u5165\u589e\u5f3a\u5904\u7406\uff0c\u4ece\u800c\u5b8c\u6210\u4e86\u5bf9\u76ee\u6807\u65b9\u6cd5\u7684\u589e\u5f3a\u3002<\/p>\n<p><strong>\u5c0f\u7ed3<\/strong><\/p>\n<p id=\"aeaoofnhgocdbnbeljkmbjdmhbcokfdb-mousedown\">AOP \u5e7f\u6cdb\u5e94\u7528\u4e8e\u5904\u7406\u4e00\u4e9b\u5177\u6709\u6a2a\u5207\u6027\u8d28\u7684\u7cfb\u7edf\u7ea7\u670d\u52a1\uff0cAOP \u7684\u51fa\u73b0\u662f\u5bf9 OOP \u7684\u826f\u597d\u8865\u5145\uff0c\u5b83\u4f7f\u5f97\u5f00\u53d1\u8005\u80fd\u7528\u66f4\u4f18\u96c5\u7684\u65b9\u5f0f\u5904\u7406\u5177\u6709\u6a2a\u5207\u6027\u8d28\u7684\u670d\u52a1\u3002\u4e0d\u7ba1\u662f\u90a3\u79cd AOP \u5b9e\u73b0\uff0c\u4e0d\u8bba\u662f AspectJ\u3001\u8fd8\u662f Spring AOP\uff0c\u5b83\u4eec\u90fd\u9700\u8981\u52a8\u6001\u5730\u751f\u6210\u4e00\u4e2a AOP \u4ee3\u7406\u7c7b\uff0c\u533a\u522b\u53ea\u662f\u751f\u6210 AOP \u4ee3\u7406\u7c7b\u7684\u65f6\u673a\u4e0d\u540c\uff1aAspectJ \u91c7\u7528\u7f16\u8bd1\u65f6\u751f\u6210 AOP \u4ee3\u7406\u7c7b\uff0c\u56e0\u6b64\u5177\u6709\u66f4\u597d\u7684\u6027\u80fd\uff0c\u4f46\u9700\u8981\u4f7f\u7528\u7279\u5b9a\u7684\u7f16\u8bd1\u5668\u8fdb\u884c\u5904\u7406\uff1b\u800c Spring AOP \u5219\u91c7\u7528\u8fd0\u884c\u65f6\u751f\u6210 AOP \u4ee3\u7406\u7c7b\uff0c\u56e0\u6b64\u65e0\u9700\u4f7f\u7528\u7279\u5b9a\u7f16\u8bd1\u5668\u8fdb\u884c\u5904\u7406\u3002\u7531\u4e8e Spring AOP \u9700\u8981\u5728\u6bcf\u6b21\u8fd0\u884c\u65f6\u751f\u6210 AOP \u4ee3\u7406\uff0c\u56e0\u6b64\u6027\u80fd\u7565\u5dee\u4e00\u4e9b\u3002<\/p>\n<p>\u5f15\u81ea\uff1a<a href=\"http:\/\/www.ibm.com\/developerworks\/cn\/java\/j-lo-springaopcglib\/index.html?ca=drs-\" target=\"_blank\">IBM Developerworks<\/a><\/p>\n<p><a href=\"http:\/\/weitaoc.com\/archives\/261\/1-13\" rel=\"attachment wp-att-276\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-276\" src=\"http:\/\/weitaoc.com\/wp-content\/uploads\/2015\/05\/1.png\" alt=\"1\" width=\"258\" height=\"151\" \/><\/a><\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"http:\/\/weitaoc.com\">\u8ff7\u8def\u7684\u8001\u9f20<\/a> &raquo; <a href=\"http:\/\/weitaoc.com\/?p=261\">\u4e00\u7bc7\u8bb2\u89e3\u975e\u5e38\u7ec6\u81f4\u7684\u6587\u7ae0-Spring AOP \u5b9e\u73b0\u539f\u7406\u4e0e CGLIB \u5e94\u7528<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb\uff1a\u00a0AOP\uff08Aspect Orient Programming\uff09\uff0c\u4e5f\u5c31\u662f\u9762\u5411\u65b9\u9762\u7f16\u7a0b\uff0c\u4f5c\u4e3a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4e00\u79cd\u8865\u5145\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u7cfb\u7edf\u4e2d\u5206\u5e03\u4e8e\u5404\u4e2a\u6a21\u5757\uff08\u4e0d\u540c\u65b9\u6cd5\uff09\u4e2d\u7684\u4ea4\u53c9\u5173\u6ce8\u70b9\u7684\u95ee\u9898\uff0c\u5728 Java EE \u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u901a\u8fc7 AOP \u6765\u5904\u7406\u4e00\u4e9b\u5177\u6709\u6a2a\u5207\u6027 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,4],"tags":[47],"class_list":["post-261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-46","category-technology","tag-spring"],"views":8682,"_links":{"self":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=261"}],"version-history":[{"count":1,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":284,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions\/284"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/media\/262"}],"wp:attachment":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}