{"id":288,"date":"2022-04-06T17:25:09","date_gmt":"2022-04-06T09:25:09","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=288"},"modified":"2026-06-19T21:39:36","modified_gmt":"2026-06-19T13:39:36","slug":"spring%e6%a1%86%e6%9e%b6%e5%ad%a6%e4%b9%a0%ef%bc%9aioc%e6%93%8d%e4%bd%9cbean%e7%ae%a1%e7%90%86-bean%e7%9a%84%e4%bd%9c%e7%94%a8%e5%9f%9f%e5%85%ad","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=288","title":{"rendered":"Spring\u6846\u67b6\u5b66\u4e60\uff1aIOC\u64cd\u4f5cBean\u7ba1\u7406-Bean\u7684\u4f5c\u7528\u57df(\u516d)"},"content":{"rendered":"<h2>\u4f5c\u7528\u57dfscope\uff1a<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u4f5c\u7528\u57df<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>singleton<\/td>\n<td>\u5728spring IoC\u5bb9\u5668\u4ec5\u5b58\u5728\u4e00\u4e2aBean\u5b9e\u4f8b\uff0cBean\u4ee5\u5355\u4f8b\u65b9\u5f0f\u5b58\u5728\uff0cbean\u4f5c\u7528\u57df\u8303\u56f4\u7684\u9ed8\u8ba4\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>prototype<\/td>\n<td>\u6bcf\u6b21\u4ece\u5bb9\u5668\u4e2d\u8c03\u7528Bean\u65f6\uff0c\u90fd\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\uff0c\u5373\u6bcf\u6b21\u8c03\u7528getBean()\u65f6\uff0c\u76f8\u5f53\u4e8e\u6267\u884cnewXxxBean()\u3002<\/td>\n<\/tr>\n<tr>\n<td>request<\/td>\n<td>\u6bcf\u6b21HTTP\u8bf7\u6c42\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Bean\uff0c\u8be5\u4f5c\u7528\u57df\u4ec5\u9002\u7528\u4e8eweb\u7684Spring WebApplicationContext\u73af\u5883\u3002<\/td>\n<\/tr>\n<tr>\n<td>session<\/td>\n<td>\u540c\u4e00\u4e2aHTTP Session\u5171\u4eab\u4e00\u4e2aBean\uff0c\u4e0d\u540cSession\u4f7f\u7528\u4e0d\u540c\u7684Bean\u3002\u8be5\u4f5c\u7528\u57df\u4ec5\u9002\u7528\u4e8eweb\u7684Spring WebApplicationContext\u73af\u5883\u3002<\/td>\n<\/tr>\n<tr>\n<td>application<\/td>\n<td>\u9650\u5b9a\u4e00\u4e2aBean\u7684\u4f5c\u7528\u57df\u4e3aServletContext\u7684\u751f\u547d\u5468\u671f\u3002\u8be5\u4f5c\u7528\u57df\u4ec5\u9002\u7528\u4e8eweb\u7684Spring WebApplicationContext\u73af\u5883\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4ee3\u7801\u5b9e\u73b0\u8bbe\u7f6e\u591a\u5b9e\u4f8b\uff1a<\/h2>\n<pre><code class=\"language-java\">&lt;bean id=&quot;book&quot; class=&quot;com.spring5.collectiontype.Book&quot; scope=&quot;prototype&quot;&gt;\n        &lt;property name=&quot;list&quot; ref=&quot;bookList&quot;&gt;&lt;\/property&gt;\n    &lt;\/bean&gt;<\/code><\/pre>\n<p>\u6267\u884c\u7ed3\u679c\uff0c\u5bf9\u8c61\u4e0d\u4e00\u81f4\uff1a<\/p>\n<pre><code class=\"language-java\">com.spring5.collectiontype.Book@4b53f538\ncom.spring5.collectiontype.Book@134593bf<\/code><\/pre>\n<p>1\u3001\u5728Spring\u91cc\u9762\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u521b\u5efa\u7684bean\u5b9e\u4f8b\u662f\u5355\u5b9e\u4f8b\u8fd8\u662f\u591a\u5b9e\u4f8b<\/p>\n<p>2\u3001\u5728Spring\u91cc\u9762\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cbean\u662f\u5355\u5b9e\u4f8b\u5bf9\u8c61<\/p>\n<h2>singleton\u548cprototype\u533a\u522b<\/h2>\n<p>\u7b2c\u4e00\uff1asingleton\u5355\u5b9e\u4f8b\uff0cprototype\u591a\u5b9e\u4f8b<br \/>\n\u7b2c\u4e8c\uff1a\u8bbe\u7f6escope\u503c\u662fsingleton\u65f6\u5019\uff0c\u52a0\u8f7dspring\u914d\u7f6e\u6587\u4ef6\u65f6\u5019\u5c31\u4f1a\u521b\u5efa\u5355\u5b9e\u4f8b\u5bf9\u8c61<br \/>\n\u8bbe\u7f6escope\u503c\u662fprototype\u65f6\u5019\uff0c\u4e0d\u662f\u5728\u52a0\u8f7dspring\u914d\u7f6e\u6587\u4ef6\u65f6\u5019\u521b\u5efa\u5bf9\u8c61\uff0c\u5728\u8c03\u7528getBean\u65b9\u6cd5\u65f6\u5019\u521b\u5efa\u591a\u5b9e\u4f8b\u5bf9\u8c61<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u7528\u57dfscope\uff1a \u4f5c\u7528\u57df \u63cf\u8ff0 singleton \u5728spring IoC\u5bb9\u5668\u4ec5\u5b58\u5728\u4e00\u4e2aBean\u5b9e\u4f8b\uff0cBea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[68],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-spring"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":2154,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions\/2154"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}