
{"id":2571,"date":"2020-12-04T14:35:11","date_gmt":"2020-12-04T06:35:11","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2571"},"modified":"2020-12-04T16:06:23","modified_gmt":"2020-12-04T08:06:23","slug":"2020javaweb%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%ef%bc%9aspring%e5%af%b9%e8%b1%a1%e5%88%9b%e5%bb%ba%e7%9a%84%e7%bb%86%e8%8a%82","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2571","title":{"rendered":"2020javaweb\u6846\u67b6\u6559\u7a0b\uff1aspring\u5bf9\u8c61\u521b\u5efa\u7684\u7ec6\u8282"},"content":{"rendered":"<h3>2020javaweb\u6846\u67b6\u6559\u7a0b\uff1aspring\u5bf9\u8c61\u521b\u5efa\u7684\u7ec6\u8282<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u5355\u4f8b\u548c\u591a\u4f8b<\/strong><\/span><\/p>\n<p>1.\u9ed8\u8ba4\u60c5\u51b5\u4e0bbean\u662f\u5355\u4f8b\u7684\uff0cscope=&#8221;singleton&#8217;;<br \/>\n2.\u591a\u4f8b\u914d\u7f6e\uff1ascope=&#8221;prototype&#8221;;<br \/>\n3.scope=&#8221;request&#8221;;<br \/>\n4.scope=&#8221;session&#8221;;<\/p>\n<pre>&lt;!-- singleton\u662f\u5355\u4f8b \u83b7\u53d6\u7684\u5bf9\u8c61\u90fd\u662f\u540c\u4e00\u4e2a\u5730\u5740 --&gt;\r\n&lt;bean name=\"users2\" class=\"entity.Users\" scope=\"singleton\"&gt;&lt;\/bean&gt;\r\n&lt;!-- prototype \u662f \u591a\u4f8b \u6bcf\u6b21\u6784\u5efa\u5bf9\u8c61\u90fd new\u4e00\u4e2a\u65b0\u7684\u5730\u5740 --&gt;\r\n&lt;bean name=\"users2\" class=\"entity.Users\" scope=\"prototype\"&gt;&lt;\/bean&gt;<\/pre>\n<p><!--more--><\/p>\n<p><span style=\"color: #ff0000;\"><strong>bean\u521b\u5efa\u6a21\u5f0f<\/strong><\/span><\/p>\n<p>singleton\u5355\u4f8b(\u9ed8\u8ba4)\uff1b<\/p>\n<p>\u5728\u540c\u4e00\u4e2aspring\u5de5\u5382\u4e2d\uff0c\u4e00\u4e2aBean\u53ea\u4f1a\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u3002<br \/>\n\u591a\u6b21getBean()\uff0c\u6216\u591a\u6b21\u6ce8\u5165\u4f7f\u7528\u7684\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u3002<br \/>\n\u968f\u5de5\u5382\u521b\u5efa\u800c\u521b\u5efa\uff0c\u968f\u5de5\u5382\u5173\u95ed\u800c\u9500\u6bc1\u3002<\/p>\n<p><span style=\"color: #ff0000;\">prototype\uff1a\u591a\u4f8b(\u539f\u578b)<\/span><\/p>\n<pre>&lt;bean class=\"bean.Users\" id=\"users\" scope=\"prototype\"\/&gt;<\/pre>\n<p>\u6bcf\u6b21getBean()\uff0c\u6216\u591a\u6b21\u6ce8\u5165\u90fd\u4f1a\u91cd\u65b0\u521b\u5efa\u5bf9\u8c61\u3002<br \/>\n\u4e0d\u968f\u5de5\u5382\u521b\u5efa\u800c\u521b\u5efa\uff0c\u4e0d\u968f\u5de5\u5382\u5173\u95ed\u800c\u9500\u6bc1<br \/>\n\u88ab\u7528\u5230\u65f6\u624d\u4f1a\u521b\u5efa\u5bf9\u8c61\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u751f\u547d\u5468\u671f<\/strong><\/span><\/p>\n<p>\u5355\u4f8bBean\uff1a\u6784\u9020(\u5de5\u5382\u542f\u52a8)&#8211;&gt;set&#8211;&gt;init&#8211;&gt;User&#8211;&gt;destory(\u9500\u6bc1)<\/p>\n<p>\u591a\u4f8bBean\uff1a\u83b7\u53d6\u65f6\u624d\u521b\u5efa&#8211;&gt;set&#8211;&gt;init&#8211;&gt;User&#8211;&gt;\u4e0d\u4f1a\u968f\u5de5\u5382\u5173\u95ed\u800c\u9500\u6bc1<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u5ef6\u8fdf\u521b\u5efa\u5bf9\u8c61<\/strong><\/span><\/p>\n<p>lazy-init=&#8221;true&#8221; \u5ef6\u8fdf\u521b\u5efa\u5bf9\u8c61\uff0c\u5bb9\u5668\u542f\u52a8\u65f6\u4e0d\u521b\u5efa\uff0c\u83b7\u53d6\u65f6\u518d\u521b\u5efa<\/p>\n<p>lazy-init=&#8221;false&#8221; \u9ed8\u8ba4\u503c\uff0c\u4e0d\u5ef6\u8fdf\u521b\u5efa\u5bf9\u8c61\uff0c\u5bb9\u5668\u542f\u52a8\u65f6\u7acb\u5373\u521b\u5efa<\/p>\n<pre>&lt;bean name=\"users2\" class=\"entity.Users\" scope=\"singleton\" lazy-init=\"true\"&gt;&lt;\/bean&gt;<\/pre>\n<p><span style=\"color: #ff0000;\">\u6ce8\uff1a\u5ef6\u8fdf\u521b\u5efa\u5bf9\u8c61\u53ea\u5bf9 \u5355\u4f8b \u6709\u6548<\/span><\/p>\n<pre>init-method=\"init\" destroy-method=\"destroy<\/pre>\n<p>init\u521d\u59cb\u5316\u65b9\u6cd5\u3001destroy\u9500\u6bc1\u65b9\u6cd5\uff0c\u9700\u8981\u8c03\u7528destroy()\u65b9\u6cd5\u6216close()\u65b9\u6cd5\uff0c\u7136\u540e\u5c06ApplicationContext\u6539\u6210AbstractApplicationContext<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020javaweb\u6846\u67b6\u6559\u7a0b\uff1aspring\u5bf9\u8c61\u521b\u5efa\u7684\u7ec6\u8282 \u5355\u4f8b\u548c\u591a\u4f8b 1.\u9ed8\u8ba4\u60c5\u51b5\u4e0bbean\u662f\u5355\u4f8b\u7684\uff0csco [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2571","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2571"}],"version-history":[{"count":3,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2571\/revisions"}],"predecessor-version":[{"id":2580,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2571\/revisions\/2580"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}