{"id":11930,"date":"2023-11-28T22:38:09","date_gmt":"2023-11-28T14:38:09","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=11930"},"modified":"2023-12-11T14:41:44","modified_gmt":"2023-12-11T06:41:44","slug":"spring-de-dan-li-shi-xian-yuan-li","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-de-dan-li-shi-xian-yuan-li\/","title":{"rendered":"Spring\u7684\u5355\u4f8b\u5b9e\u73b0\u539f\u7406\uff1f"},"content":{"rendered":"<p>\u5728 Spring \u4e2d\uff0c\u5355\u4f8b\u6a21\u5f0f\u662f\u4e00\u79cd\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5b83\u786e\u4fdd\u4e00\u4e2a\u7c7b\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u751f\u547d\u5468\u671f\u5185\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u3002Spring \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u901a\u8fc7 Spring \u5bb9\u5668\u7ba1\u7406\u7684 Bean \u90fd\u662f\u5355\u4f8b\u7684\uff0c\u5373\u5728\u5bb9\u5668\u4e2d\u53ea\u5b58\u5728\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<p>Spring \u5355\u4f8b\u6a21\u5f0f\u7684\u5b9e\u73b0\u539f\u7406\u4e3b\u8981\u4f9d\u8d56\u4e8e Spring \u5bb9\u5668\u7684\u5bf9\u8c61\u7ba1\u7406\u673a\u5236\u548cBean\u7684\u4f5c\u7528\u57df\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f Spring \u5355\u4f8b\u5b9e\u73b0\u7684\u4e00\u4e9b\u5173\u952e\u70b9\uff1a<\/p>\n<ol>\n<li>\n<strong>\u9ed8\u8ba4\u5355\u4f8b\uff1a<\/strong> Spring \u5bb9\u5668\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u521b\u5efa\u7684 Bean \u662f\u5355\u4f8b\u7684\uff0c\u5373\u5728\u6574\u4e2a\u5bb9\u5668\u4e2d\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u3002\u8fd9\u662f\u56e0\u4e3a Spring \u5bb9\u5668\u4f1a\u7f13\u5b58\u5df2\u7ecf\u521b\u5efa\u7684 Bean \u5b9e\u4f8b\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u8bf7\u6c42\u90fd\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\u3002\n<\/li>\n<li>\n<strong>Bean \u7684\u4f5c\u7528\u57df\uff1a<\/strong> Spring \u63d0\u4f9b\u4e86\u591a\u79cd Bean \u7684\u4f5c\u7528\u57df\uff0c\u5305\u62ec\u5355\u4f8b\uff08singleton\uff09\u3001\u539f\u578b\uff08prototype\uff09\u3001\u4f1a\u8bdd\uff08session\uff09\u3001\u8bf7\u6c42\uff08request\uff09\u7b49\u3002\u5176\u4e2d\uff0c\u5355\u4f8b\u4f5c\u7528\u57df\u662f\u9ed8\u8ba4\u7684\u4f5c\u7528\u57df\u3002\n<\/li>\n<li>\n<strong>\u5bb9\u5668\u7f13\u5b58\uff1a<\/strong> Spring \u5bb9\u5668\u5728\u521d\u59cb\u5316\u65f6\u4f1a\u521b\u5efa\u5e76\u7f13\u5b58\u5355\u4f8b Bean\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5176\u4ed6\u7ec4\u4ef6\u9700\u8981\u8be5 Bean \u65f6\uff0c\u5bb9\u5668\u4f1a\u8fd4\u56de\u7f13\u5b58\u7684\u5b9e\u4f8b\u800c\u4e0d\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\u3002\n<\/li>\n<li>\n<strong>ApplicationContext\uff1a<\/strong> \u5728\u4f7f\u7528 <code>ApplicationContext<\/code> \u63a5\u53e3\u4f5c\u4e3a Spring \u5bb9\u5668\u65f6\uff0c\u5b83\u4f1a\u9ed8\u8ba4\u7ba1\u7406\u5355\u4f8b Bean\u3002<code>ApplicationContext<\/code> \u7684\u5b9e\u73b0\u7c7b\uff0c\u5982 <code>ClassPathXmlApplicationContext<\/code>\u3001<code>AnnotationConfigApplicationContext<\/code>\uff0c\u4f1a\u5728\u521d\u59cb\u5316\u65f6\u521b\u5efa\u5e76\u7f13\u5b58\u5355\u4f8b Bean\u3002\n<\/li>\n<li>\n<strong>\u540c\u4e00\u5bb9\u5668\u4e2d\u7684\u5355\u4f8b\uff1a<\/strong> Spring \u5bb9\u5668\u4e2d\u7684\u5355\u4f8b\u662f\u5728\u5bb9\u5668\u7ea7\u522b\u7684\uff0c\u5373\u540c\u4e00\u4e2a\u5bb9\u5668\u4e2d\u7684\u6240\u6709 Bean \u90fd\u5171\u4eab\u540c\u4e00\u4e2a\u5355\u4f8b\u5b9e\u4f8b\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a Spring \u5bb9\u5668\uff0c\u5b83\u4eec\u5404\u81ea\u7ba1\u7406\u81ea\u5df1\u7684\u5355\u4f8b\u5b9e\u4f8b\u3002\n<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5c3d\u7ba1 Spring \u9ed8\u8ba4\u662f\u5355\u4f8b\u6a21\u5f0f\uff0c\u4f46\u4e0d\u662f\u6240\u6709\u7684 Bean \u90fd\u9002\u5408\u4f5c\u4e3a\u5355\u4f8b\u3002\u6709\u4e9b Bean\uff0c\u7279\u522b\u662f\u72b6\u6001\u4e0d\u53ef\u53d8\u7684 Bean \u6216\u8005\u65e0\u72b6\u6001\u7684\u670d\u52a1\uff0c\u66f4\u9002\u5408\u88ab\u5b9a\u4e49\u4e3a\u5355\u4f8b\u3002\u800c\u5bf9\u4e8e\u4f1a\u53d1\u751f\u72b6\u6001\u53d8\u5316\u7684 Bean\uff0c\u53ef\u80fd\u9700\u8981\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u4f5c\u7528\u57df\uff0c\u5982\u539f\u578b\u6a21\u5f0f\uff08prototype\uff09\u3002<\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u6216\u4f7f\u7528\u6ce8\u89e3\u65f6\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cSpring \u7684 Bean \u662f\u5355\u4f8b\u7684\uff0c\u4f46\u5f00\u53d1\u8005\u4e5f\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e <code>@Scope(&quot;prototype&quot;)<\/code> \u6ce8\u89e3\u6216\u5728 XML \u4e2d\u4f7f\u7528 <code>&lt;bean scope=&quot;prototype&quot;&gt;<\/code> \u660e\u786e\u6307\u5b9a\u4e3a\u539f\u578b\u4f5c\u7528\u57df\uff0c\u4ee5\u5b9e\u73b0\u975e\u5355\u4f8b\u7684 Bean\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Spring \u4e2d\uff0c\u5355\u4f8b\u6a21\u5f0f\u662f\u4e00\u79cd\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5b83\u786e\u4fdd\u4e00\u4e2a\u7c7b\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u751f\u547d\u5468\u671f\u5185\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\u3002Spring  [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-11930","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=11930"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11930\/revisions"}],"predecessor-version":[{"id":37512,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11930\/revisions\/37512"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=11930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=11930"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=11930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}