{"id":12100,"date":"2023-11-28T22:43:26","date_gmt":"2023-11-28T14:43:26","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=12100"},"modified":"2023-12-11T15:24:41","modified_gmt":"2023-12-11T07:24:41","slug":"spring-zhong-beanfactory-he-applicationcontext-you","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-zhong-beanfactory-he-applicationcontext-you\/","title":{"rendered":"Spring \u4e2d BeanFactory \u548c ApplicationContext \u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p><code>BeanFactory<\/code>\u548c<code>ApplicationContext<\/code>\u90fd\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u7ba1\u7406Bean\u7684\u5bb9\u5668\uff0c\u4f46\u5b83\u4eec\u6709\u4e00\u4e9b\u91cd\u8981\u7684\u533a\u522b\uff0c\u4e3b\u8981\u6d89\u53ca\u5230\u529f\u80fd\u548c\u6027\u80fd\u65b9\u9762\uff1a<\/p>\n<ol>\n<li>\n<strong>\u5b9e\u73b0\u63a5\u53e3\uff1a<\/strong><\/p>\n<ul>\n<li><code>BeanFactory<\/code>\u662fSpring IoC\u5bb9\u5668\u7684\u57fa\u7840\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u6700\u57fa\u672c\u7684IoC\u529f\u80fd\u3002<code>ApplicationContext<\/code>\u63a5\u53e3\u662f<code>BeanFactory<\/code>\u7684\u5b50\u63a5\u53e3\uff0c\u6269\u5c55\u4e86<code>BeanFactory<\/code>\u7684\u529f\u80fd\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u4f01\u4e1a\u7ea7\u7279\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u5ef6\u8fdf\u52a0\u8f7d\uff1a<\/strong><\/p>\n<ul>\n<li>\n<code>BeanFactory<\/code>\u91c7\u7528\u5ef6\u8fdf\u52a0\u8f7d\uff08lazy-loading\uff09\u7b56\u7565\uff0c\u5373\u5728\u771f\u6b63\u9700\u8981\u4f7f\u7528Bean\u65f6\u624d\u8fdb\u884c\u521d\u59cb\u5316\u3002\u8fd9\u610f\u5473\u7740\u5728\u5bb9\u5668\u542f\u52a8\u65f6\uff0c\u4e0d\u4f1a\u5b9e\u4f8b\u5316\u6240\u6709\u7684Bean\uff0c\u800c\u662f\u7b49\u5230\u7b2c\u4e00\u6b21\u8bf7\u6c42\u65f6\u624d\u521b\u5efa\u3002\n<\/li>\n<li>\n<code>ApplicationContext<\/code>\u5728\u5bb9\u5668\u542f\u52a8\u65f6\u4f1a\u9884\u5148\u5b9e\u4f8b\u5316\u6240\u6709\u7684\u5355\u4f8bBean\u3002\u8fd9\u4f7f\u5f97\u5728\u542f\u52a8\u9636\u6bb5\u5c31\u80fd\u591f\u68c0\u6d4b\u5230\u914d\u7f6e\u95ee\u9898\uff0c\u4f46\u53ef\u80fd\u4f1a\u5bfc\u81f4\u542f\u52a8\u65f6\u95f4\u8f83\u957f\u3002\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u6269\u5c55\u6027\uff1a<\/strong><\/p>\n<ul>\n<li><code>ApplicationContext<\/code>\u662f<code>BeanFactory<\/code>\u7684\u5b50\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u4f01\u4e1a\u7ea7\u529f\u80fd\uff0c\u5982\u4e8b\u4ef6\u4f20\u64ad\u3001AOP\uff08Aspect-Oriented Programming\uff09\u3001\u6d88\u606f\u6e90\uff08MessageSource\uff09\u7b49\u3002<code>ApplicationContext<\/code>\u662f\u66f4\u9ad8\u7ea7\u522b\u3001\u66f4\u5f3a\u5927\u7684\u5bb9\u5668\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u81ea\u52a8\u88c5\u914d\uff1a<\/strong><\/p>\n<ul>\n<li><code>ApplicationContext<\/code>\u76f8\u5bf9\u4e8e<code>BeanFactory<\/code>\u63d0\u4f9b\u4e86\u66f4\u4e30\u5bcc\u7684\u81ea\u52a8\u88c5\u914d\u529f\u80fd\u3002<code>BeanFactory<\/code>\u4e3b\u8981\u652f\u6301byType\u548cbyName\u4e24\u79cd\u57fa\u672c\u7684\u81ea\u52a8\u88c5\u914d\u65b9\u5f0f\uff0c\u800c<code>ApplicationContext<\/code>\u5728\u6b64\u57fa\u7840\u4e0a\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u9009\u9879\uff0c\u5982\u6784\u9020\u51fd\u6570\u81ea\u52a8\u88c5\u914d\u3001\u57fa\u4e8e\u6ce8\u89e3\u7684\u81ea\u52a8\u88c5\u914d\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u56fd\u9645\u5316\u652f\u6301\uff1a<\/strong><\/p>\n<ul>\n<li><code>ApplicationContext<\/code>\u63d0\u4f9b\u4e86\u5bf9\u56fd\u9645\u5316\u7684\u652f\u6301\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6d88\u606f\u8d44\u6e90\u7684\u67e5\u627e\u548c\u5904\u7406\u3002<code>MessageSource<\/code>\u63a5\u53e3\u63d0\u4f9b\u4e86\u8fd9\u4e9b\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>Web\u5e94\u7528\u652f\u6301\uff1a<\/strong><\/p>\n<ul>\n<li><code>WebApplicationContext<\/code>\u662f<code>ApplicationContext<\/code>\u7684\u5b50\u63a5\u53e3\uff0c\u4e13\u95e8\u7528\u4e8e\u5728Web\u5e94\u7528\u4e2d\u4f7f\u7528\u3002\u5b83\u63d0\u4f9b\u4e86\u4e0eWeb\u76f8\u5173\u7684\u529f\u80fd\uff0c\u5982Servlet\u4e0a\u4e0b\u6587\u521d\u59cb\u5316\u3001\u6587\u4ef6\u4e0a\u4f20\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u603b\u4f53\u6765\u8bf4\uff0c<code>ApplicationContext<\/code>\u662f\u66f4\u4e3a\u5f3a\u5927\u548c\u5168\u9762\u7684Spring\u5bb9\u5668\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\u3002\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u901a\u5e38\u66f4\u503e\u5411\u4e8e\u4f7f\u7528<code>ApplicationContext<\/code>\uff0c\u9664\u975e\u6709\u7279\u6b8a\u7684\u6027\u80fd\u8981\u6c42\u6216\u9700\u8981\u66f4\u7ec6\u7c92\u5ea6\u7684\u63a7\u5236\uff0c\u624d\u4f1a\u8003\u8651\u4f7f\u7528\u66f4\u57fa\u7840\u7684<code>BeanFactory<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BeanFactory\u548cApplicationContext\u90fd\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u7ba1\u7406Bean\u7684\u5bb9\u5668\uff0c\u4f46\u5b83 [&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-12100","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12100","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=12100"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12100\/revisions"}],"predecessor-version":[{"id":47852,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12100\/revisions\/47852"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=12100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=12100"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=12100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}