{"id":34523,"date":"2024-11-26T14:53:55","date_gmt":"2024-11-26T06:53:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34523\/"},"modified":"2024-11-26T14:53:55","modified_gmt":"2024-11-26T06:53:55","slug":"spring-ioc-%e4%b8%ad%e6%b3%a8%e5%85%a5%e7%9b%b8%e5%90%8c%e5%90%8d%e7%a7%b0%e7%9a%84-bean-%e4%bc%9a%e5%af%bc%e8%87%b4%e4%bb%80%e4%b9%88%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34523\/","title":{"rendered":"Spring IOC \u4e2d\u6ce8\u5165\u76f8\u540c\u540d\u79f0\u7684 Bean \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173053318356125.jpg\" class=\"aligncenter\" title=\"Spring IOC \u4e2d\u6ce8\u5165\u76f8\u540c\u540d\u79f0\u7684 Bean \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"Spring IOC \u4e2d\u6ce8\u5165\u76f8\u540c\u540d\u79f0\u7684 Bean \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>amq \u6d88\u606f\u4e2d\u95f4\u4ef6\u4e2d\u4f7f\u7528 spring ioc \u65f6\u7684\u9519\u8bef<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 amq \u6d88\u606f\u4e2d\u95f4\u4ef6\u7684\u9879\u76ee\u4e2d\uff0c\u4e00\u4f4d\u5f00\u53d1\u8005\u8bd5\u56fe\u5728 spring ioc \u5bb9\u5668\u4e2d\u6ce8\u5165\u4e24\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 bean\uff0c\u4ece\u800c\u5bfc\u81f4\u4e86\u9519\u8bef\u3002\u9519\u8bef\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre>org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [interface org.springframework.data.jpa.repository.JpaRepository] is defined: expected single matching bean but found 2:<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u8be5\u9519\u8bef\u8868\u660e spring \u65e0\u6cd5\u627e\u5230\u5177\u6709\u6307\u5b9a\u540d\u79f0\u548c\u7c7b\u578b\u7684\u552f\u4e00 bean\u3002\u5728 spring ioc \u5bb9\u5668\u4e2d\uff0cbean \u7684\u540d\u79f0\u5fc5\u987b\u662f\u552f\u4e00\u7684\u3002\u6b64\u9519\u8bef\u901a\u5e38\u53d1\u751f\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5728\u914d\u7f6e\u4e2d\u4e0d\u5c0f\u5fc3\u4f7f\u7528\u4e86\u76f8\u540c\u7684 bean \u540d\u79f0\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u4e2d\u624b\u52a8\u521b\u5efa\u4e86 bean\uff0c\u5e76\u4e14\u4f7f\u7528\u4e86\u76f8\u540c\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u9519\u8bef\uff0c\u9700\u8981\u786e\u4fdd spring \u914d\u7f6e\u4e2d\u6216\u4ee3\u7801\u4e2d\u6ca1\u6709\u4f7f\u7528\u76f8\u540c\u7684 bean \u540d\u79f0\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5 spring \u914d\u7f6e\u6587\u4ef6\uff0c\u786e\u4fdd\u6ca1\u6709\u5b9a\u4e49\u591a\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 bean\u3002<\/li>\n<li>\u68c0\u67e5\u4ee3\u7801\uff0c\u786e\u4fdd\u6ca1\u6709\u624b\u52a8\u521b\u5efa\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 bean\u3002<\/li>\n<li>\u4fee\u6539\u5176\u4e2d\u4e00\u4e2a bean \u7684\u540d\u79f0\uff0c\u4f7f\u5176\u4e0e\u53e6\u4e00\u4e2a bean \u533a\u5206\u5f00\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fSpring IOC \u4e2d\u6ce8\u5165\u76f8\u540c\u540d\u79f0\u7684 Bean \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>amq \u6d88\u606f\u4e2d\u95f4\u4ef6\u4e2d\u4f7f\u7528 spring ioc \u65f6\u7684\u9519\u8bef \u95ee\u9898\uff1a \u5728\u4f7f\u7528 amq \u6d88\u606f\u4e2d\u95f4\u4ef6\u7684\u9879\u76ee\u4e2d\uff0c\u4e00\u4f4d\u5f00\u53d1\u8005\u8bd5\u56fe\u5728 spring ioc \u5bb9\u5668\u4e2d\u6ce8\u5165\u4e24\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 bean\uff0c\u4ece\u800c\u5bfc\u81f4\u4e86\u9519\u8bef\u3002\u9519\u8bef\u4fe1\u606f\u5982\u4e0b\uff1a org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [interface org.springframework.data.jpa.repository.JpaRepository] is defined: expected single matching bean but found 2: \u767b\u5f55\u540e\u590d\u5236 \u5206\u6790\uff1a \u8be5\u9519\u8bef\u8868\u660e spring \u65e0\u6cd5\u627e\u5230\u5177\u6709\u6307\u5b9a\u540d\u79f0\u548c\u7c7b\u578b\u7684\u552f\u4e00 bean\u3002\u5728 spring ioc \u5bb9\u5668\u4e2d\uff0cbean \u7684\u540d\u79f0\u5fc5\u987b\u662f\u552f\u4e00\u7684\u3002\u6b64\u9519\u8bef\u901a\u5e38\u53d1\u751f\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\uff1a \u5728\u914d\u7f6e\u4e2d\u4e0d\u5c0f\u5fc3\u4f7f\u7528\u4e86\u76f8\u540c\u7684 bean \u540d\u79f0\u3002 \u5728\u4ee3\u7801\u4e2d\u624b\u52a8\u521b\u5efa\u4e86 bean\uff0c\u5e76\u4e14\u4f7f\u7528\u4e86\u76f8\u540c\u7684\u540d\u79f0\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u89e3\u51b3\u6b64\u9519\u8bef\uff0c\u9700\u8981\u786e\u4fdd spring \u914d\u7f6e\u4e2d\u6216\u4ee3\u7801\u4e2d\u6ca1\u6709\u4f7f\u7528\u76f8\u540c\u7684 bean \u540d\u79f0\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u68c0\u67e5 spring \u914d\u7f6e\u6587\u4ef6\uff0c\u786e\u4fdd\u6ca1\u6709\u5b9a\u4e49\u591a\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 bean\u3002 [&hellip;]<\/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-34523","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34523","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=34523"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34523\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}