{"id":64846,"date":"2025-05-03T14:32:30","date_gmt":"2025-05-03T06:32:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64846\/"},"modified":"2025-05-03T14:32:30","modified_gmt":"2025-05-03T06:32:30","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bb%8e-spring-%e4%b8%8a%e4%b8%8b%e6%96%87%e8%8e%b7%e5%8f%96%e7%9a%84-bean-%e5%8f%8d%e5%b0%84%e5%90%8e%e6%8b%bf%e4%b8%8d%e5%88%b0%e5%b1%9e%e6%80%a7%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64846\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4ece Spring \u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173080606454229.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u4ece Spring \u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u4ece Spring \u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u4ece\u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f<\/strong><\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u6d89\u53ca Spring \u7684 Bean \u4ee3\u7406\u673a\u5236\u3002\u5f53\u4f60\u4ece\u4e00\u4e2a ApplicationContext \u4e2d\u4f7f\u7528 getBean() \u65b9\u6cd5\u83b7\u53d6\u4e00\u4e2a Bean \u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u4ee3\u7406\u7c7b\u3002\u4ee3\u7406\u7c7b\u662f Spring \u4e3a\u7ba1\u7406 Bean \u7684\u751f\u547d\u5468\u671f\u548c\u63d0\u4f9b\u5176\u4ed6\u7279\u6027\u800c\u521b\u5efa\u7684\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u4f7f\u7528\u4ee3\u7406\u7c7b\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5373\u65e0\u6cd5\u4f7f\u7528\u53cd\u5c04\u6765\u83b7\u53d6\u5176\u771f\u5b9e\u7c7b\u7684\u5b57\u6bb5\u3002\u8fd9\u662f\u56e0\u4e3a\u53cd\u5c04\u53ea\u89e3\u6790\u4ee3\u7406\u7c7b\u81ea\u8eab\uff0c\u800c\u65e0\u6cd5\u8bbf\u95ee\u771f\u5b9e\u7c7b\u7684\u5b57\u6bb5\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p>\u4f7f\u7528 class.getSuperclass() \u83b7\u53d6\u771f\u5b9e\u7c7b\u7684\u7c7b\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528\u53cd\u5c04\u53bb\u89e3\u6790\u8be5\u7c7b\u3002<br \/>\u4f7f\u7528 AOP \u4ee3\u7406\uff0c\u5bf9\u76ee\u6807\u7c7b\u8fdb\u884c\u589e\u5f3a\u800c\u4e0d\u662f\u521b\u5efa\u4e00\u4e2a\u4ee3\u7406\u7c7b\u3002<br \/>\u4f7f\u7528 @IgnoreAdvice \u6ce8\u89e3\u6765\u5ffd\u7565\u5bf9\u8be5\u7c7b\u7684\u4ee3\u7406\u3002<br \/>\u5728\u83b7\u53d6 Bean \u65f6\u4f7f\u7528 BeanFactory \u800c\u4e0d\u662f ApplicationContext\uff0cBeanFactory \u4e0d\u4f1a\u521b\u5efa\u4ee3\u7406\u7c7b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4ece Spring \u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u4ece\u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f \u8fd9\u4e2a\u95ee\u9898\u6d89\u53ca Spring \u7684 Bean \u4ee3\u7406\u673a\u5236\u3002\u5f53\u4f60\u4ece\u4e00\u4e2a ApplicationContext \u4e2d\u4f7f\u7528 getBean() \u65b9\u6cd5\u83b7\u53d6\u4e00\u4e2a Bean \u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u4ee3\u7406\u7c7b\u3002\u4ee3\u7406\u7c7b\u662f Spring \u4e3a\u7ba1\u7406 Bean \u7684\u751f\u547d\u5468\u671f\u548c\u63d0\u4f9b\u5176\u4ed6\u7279\u6027\u800c\u521b\u5efa\u7684\u3002 \u4f46\u662f\uff0c\u4f7f\u7528\u4ee3\u7406\u7c7b\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5373\u65e0\u6cd5\u4f7f\u7528\u53cd\u5c04\u6765\u83b7\u53d6\u5176\u771f\u5b9e\u7c7b\u7684\u5b57\u6bb5\u3002\u8fd9\u662f\u56e0\u4e3a\u53cd\u5c04\u53ea\u89e3\u6790\u4ee3\u7406\u7c7b\u81ea\u8eab\uff0c\u800c\u65e0\u6cd5\u8bbf\u95ee\u771f\u5b9e\u7c7b\u7684\u5b57\u6bb5\u3002 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528 class.getSuperclass() \u83b7\u53d6\u771f\u5b9e\u7c7b\u7684\u7c7b\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528\u53cd\u5c04\u53bb\u89e3\u6790\u8be5\u7c7b\u3002\u4f7f\u7528 AOP \u4ee3\u7406\uff0c\u5bf9\u76ee\u6807\u7c7b\u8fdb\u884c\u589e\u5f3a\u800c\u4e0d\u662f\u521b\u5efa\u4e00\u4e2a\u4ee3\u7406\u7c7b\u3002\u4f7f\u7528 @IgnoreAdvice \u6ce8\u89e3\u6765\u5ffd\u7565\u5bf9\u8be5\u7c7b\u7684\u4ee3\u7406\u3002\u5728\u83b7\u53d6 Bean \u65f6\u4f7f\u7528 BeanFactory \u800c\u4e0d\u662f ApplicationContext\uff0cBeanFactory \u4e0d\u4f1a\u521b\u5efa\u4ee3\u7406\u7c7b\u3002 \u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4ece Spring \u4e0a\u4e0b\u6587\u83b7\u53d6\u7684 Bean \u53cd\u5c04\u540e\u62ff\u4e0d\u5230\u5c5e\u6027\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-64846","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=64846"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64846\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}