{"id":36040,"date":"2024-11-26T12:57:04","date_gmt":"2024-11-26T04:57:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36040\/"},"modified":"2024-11-26T12:57:04","modified_gmt":"2024-11-26T04:57:04","slug":"spring-boot-%e9%a1%b9%e7%9b%ae%e4%b8%ad-serviceimpl-%e9%87%8d%e5%a4%8d%e8%af%bb%e5%8f%96-bean-%e5%af%b9%e8%b1%a1%e9%97%ae%e9%a2%98%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8-resource","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36040\/","title":{"rendered":"Spring Boot \u9879\u76ee\u4e2d ServiceImpl \u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 @Resource \u6ce8\u89e3\u4f1a\u9020\u6210\u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173088380610287.jpg\" class=\"aligncenter\" title=\"Spring Boot \u9879\u76ee\u4e2d ServiceImpl \u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 @Resource \u6ce8\u89e3\u4f1a\u9020\u6210\u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\uff1f\u63d2\u56fe\" alt=\"Spring Boot \u9879\u76ee\u4e2d ServiceImpl \u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 @Resource \u6ce8\u89e3\u4f1a\u9020\u6210\u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>spring boot \u9879\u76ee\u4e2d serviceimpl \u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u6211\u5728 spring boot \u9879\u76ee\u4e2d\u4f7f\u7528 @service, @mapper \u548c @controller \u6ce8\u89e3\uff0c\u4f46\u51fa\u73b0\u4e86\u5f02\u5e38\u63d0\u793a\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002\u8fd9\u662f\u4ec0\u4e48\u539f\u56e0\uff1f<\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u4f7f\u7528\u4e86 @resource \u6ce8\u89e3\u3002@resource \u7528\u4e8e\u81ea\u52a8\u88c5\u914d bean\uff0c\u5b83\u53ef\u4ee5\u6839\u636e\u7c7b\u578b\u6216\u540d\u79f0\u6765\u67e5\u627e bean\u3002\u5728\u4f60\u7684\u60c5\u51b5\u4e0b\uff0cserviceimpl \u53ef\u80fd\u5728\u4e24\u4e2a\u4f4d\u7f6e\u88ab\u88c5\u914d\uff1acontroller \u548c mapper\u3002\u8fd9\u4f1a\u5bfc\u81f4\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li> <strong>\u4f7f\u7528 @autowired \u6ce8\u89e3\uff1a<\/strong>@autowired \u6ce8\u89e3\u4e5f\u53ef\u4ee5\u7528\u4e8e\u81ea\u52a8\u88c5\u914d bean\uff0c\u4f46\u5b83\u53ea\u6839\u636e\u7c7b\u578b\u8fdb\u884c\u5339\u914d\uff0c\u4e0d\u4f1a\u6839\u636e\u540d\u79f0\u8fdb\u884c\u5339\u914d\u3002\u8fd9\u5c06\u907f\u514d\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002<\/li>\n<li> <strong>\u663e\u5f0f\u6307\u5b9a bean \u540d\u79f0\uff1a<\/strong>\u53ef\u4ee5\u901a\u8fc7\u5728 @resource \u6ce8\u89e3\u4e2d\u6307\u5b9a bean \u540d\u79f0\u6765\u907f\u514d\u51b2\u7a81\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre>@Resource(name = \"myServiceImpl\")\nprivate ServiceImpl serviceImpl;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u4f7f\u7528\u5176\u4ed6\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6\uff1a<\/strong>spring boot \u63d0\u4f9b\u4e86\u5176\u4ed6\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6\uff0c\u4f8b\u5982 dagger \u6216 guice\uff0c\u5b83\u4eec\u53ef\u4ee5\u63d0\u4f9b\u66f4\u660e\u786e\u7684\u4f9d\u8d56\u7ba1\u7406\u3002<\/li>\n<\/ul>\n<p>\u53c2\u8003 [\u8fd9\u7bc7\u6587\u7ae0](https:\/\/blog.csdn.net\/weixin_38237873\/article\/detls\/83650429) \u4ee5\u4e86\u89e3\u5173\u4e8e @resource \u6ce8\u89e3\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSpring Boot \u9879\u76ee\u4e2d ServiceImpl \u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u4f7f\u7528 @Resource \u6ce8\u89e3\u4f1a\u9020\u6210\u91cd\u590d\u8bfb\u53d6 Bean \u5bf9\u8c61\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>spring boot \u9879\u76ee\u4e2d serviceimpl \u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61 \u95ee\u9898\uff1a \u6211\u5728 spring boot \u9879\u76ee\u4e2d\u4f7f\u7528 @service, @mapper \u548c @controller \u6ce8\u89e3\uff0c\u4f46\u51fa\u73b0\u4e86\u5f02\u5e38\u63d0\u793a\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002\u8fd9\u662f\u4ec0\u4e48\u539f\u56e0\uff1f \u89e3\u91ca\uff1a \u8fd9\u662f\u56e0\u4e3a\u4f7f\u7528\u4e86 @resource \u6ce8\u89e3\u3002@resource \u7528\u4e8e\u81ea\u52a8\u88c5\u914d bean\uff0c\u5b83\u53ef\u4ee5\u6839\u636e\u7c7b\u578b\u6216\u540d\u79f0\u6765\u67e5\u627e bean\u3002\u5728\u4f60\u7684\u60c5\u51b5\u4e0b\uff0cserviceimpl \u53ef\u80fd\u5728\u4e24\u4e2a\u4f4d\u7f6e\u88ab\u88c5\u914d\uff1acontroller \u548c mapper\u3002\u8fd9\u4f1a\u5bfc\u81f4\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a \u4f7f\u7528 @autowired \u6ce8\u89e3\uff1a@autowired \u6ce8\u89e3\u4e5f\u53ef\u4ee5\u7528\u4e8e\u81ea\u52a8\u88c5\u914d bean\uff0c\u4f46\u5b83\u53ea\u6839\u636e\u7c7b\u578b\u8fdb\u884c\u5339\u914d\uff0c\u4e0d\u4f1a\u6839\u636e\u540d\u79f0\u8fdb\u884c\u5339\u914d\u3002\u8fd9\u5c06\u907f\u514d\u91cd\u590d\u8bfb\u53d6 bean \u5bf9\u8c61\u3002 \u663e\u5f0f\u6307\u5b9a bean \u540d\u79f0\uff1a\u53ef\u4ee5\u901a\u8fc7\u5728 @resource \u6ce8\u89e3\u4e2d\u6307\u5b9a bean \u540d\u79f0\u6765\u907f\u514d\u51b2\u7a81\u3002\u4f8b\u5982\uff1a @Resource(name = &#8220;myServiceImpl&#8221;) private ServiceImpl serviceImpl; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5176\u4ed6\u4f9d\u8d56\u6ce8\u5165\u6846\u67b6\uff1aspring [&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-36040","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36040","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=36040"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36040\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}