{"id":94272,"date":"2026-08-14T06:48:56","date_gmt":"2026-08-13T22:48:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/94272.html"},"modified":"2026-08-14T06:48:56","modified_gmt":"2026-08-13T22:48:56","slug":"%e3%80%8ajava-100-%e5%a4%a9%e8%bf%9b%e9%98%b6%e4%b9%8b%e8%b7%af%e3%80%8b%e7%ac%ac73%e7%af%87%ef%bc%9aspring-ioc%e5%ae%b9%e5%99%a8%ef%bc%882026%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/94272.html","title":{"rendered":"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09"},"content":{"rendered":"<h3>\u7b2c73\u7bc7&#xff1a;Spring IoC\u5bb9\u5668&#xff08;2026\u7248&#xff09;<\/h3>\n<p>&#x1f4cc; \u7cfb\u5217\u5bfc\u822a&#xff1a;\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u5b8c\u6574\u76ee\u5f55 | \u2b05\ufe0f \u4e0a\u4e00\u7bc7&#xff1a;\u7b2c72\u7bc7&#xff1a;JavaWeb\u9762\u8bd5\u9ad8\u9891\u9898 | \u27a1\ufe0f \u4e0b\u4e00\u7bc7&#xff1a;\u7b2c74\u7bc7&#xff1a;Bean\u751f\u547d\u5468\u671f&#xff08;\u5f85\u53d1\u5e03&#xff09;<\/p>\n<h4>&#x1f5fa;\ufe0f \u672c\u6587\u9605\u8bfb\u5730\u56fe&#xff08;3 \u5206\u949f\u901f\u89c8&#xff09;<\/h4>\n<p>\u7b2c72\u7bc7\u5b8c\u6210\u4e86JavaWeb\u4e13\u9898\u7684\u6536\u5b98&#xff0c;\u672c\u7bc7\u6b63\u5f0f\u5f00\u542f Spring\u5168\u5bb6\u6876\u4e13\u9898\u3002Spring\u662fJava\u540e\u7aef\u5f00\u53d1\u7684\u4e8b\u5b9e\u6807\u51c6&#xff0c;\u800cIoC\u5bb9\u5668\u662fSpring\u6700\u6838\u5fc3\u7684\u57fa\u77f3\u2014\u2014\u7406\u89e3\u4e86IoC\u5bb9\u5668&#xff0c;\u5c31\u7406\u89e3\u4e86Spring\u7684&#034;\u5fc3\u810f&#034;&#xff1a;<\/p>\n<table>\n<tr>\u6a21\u5757\u6838\u5fc3\u95ee\u9898\u4e00\u53e5\u8bdd\u56de\u7b54<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">IoC\u662f\u4ec0\u4e48<\/td>\n<td align=\"left\">\u63a7\u5236\u53cd\u8f6c\u5230\u5e95\u53cd\u8f6c\u4e86\u4ec0\u4e48&#xff1f;<\/td>\n<td align=\"left\">\u5bf9\u8c61\u7684\u521b\u5efa\u6743\u4ece&#034;\u81ea\u5df1new&#034;\u53cd\u8f6c\u7ed9&#034;\u5bb9\u5668\u7ba1\u7406&#034;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">DI\u662f\u4ec0\u4e48<\/td>\n<td align=\"left\">\u4f9d\u8d56\u6ce8\u5165\u548cIoC\u4ec0\u4e48\u5173\u7cfb&#xff1f;<\/td>\n<td align=\"left\">DI\u662fIoC\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u5bb9\u5668\u628a\u4f9d\u8d56&#034;\u6ce8\u5165&#034;\u7ed9\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">BeanFactory vs ApplicationContext<\/td>\n<td align=\"left\">\u4e24\u4e2a\u5bb9\u5668\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/td>\n<td align=\"left\">BeanFactory\u662f&#034;\u57fa\u7840\u6b3e&#034;&#xff08;\u61d2\u52a0\u8f7d&#xff09;&#xff0c;ApplicationContext\u662f&#034;\u65d7\u8230\u6b3e&#034;&#xff08;\u9884\u52a0\u8f7d&#043;\u4f01\u4e1a\u7ea7\u529f\u80fd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Bean\u662f\u4ec0\u4e48<\/td>\n<td align=\"left\">Spring\u91cc\u7684Bean\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f;<\/td>\n<td align=\"left\">\u88abSpring IoC\u5bb9\u5668\u7ba1\u7406\u7684Java\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Bean\u751f\u547d\u5468\u671f<\/td>\n<td align=\"left\">Bean\u4ece\u751f\u5230\u6b7b\u7ecf\u5386\u4ec0\u4e48&#xff1f;<\/td>\n<td align=\"left\">\u5b9e\u4f8b\u5316\u2192\u5c5e\u6027\u586b\u5145\u2192\u521d\u59cb\u5316\u2192\u4f7f\u7528\u2192\u9500\u6bc1<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u4e09\u79cd\u914d\u7f6e\u65b9\u5f0f<\/td>\n<td align=\"left\">\u600e\u4e48\u544a\u8bc9Spring\u8981\u7ba1\u7406\u54ea\u4e9b\u5bf9\u8c61&#xff1f;<\/td>\n<td align=\"left\">XML\u914d\u7f6e\u3001\u6ce8\u89e3\u914d\u7f6e\u3001Java\u914d\u7f6e&#xff08;&#064;Configuration &#043; &#064;Bean&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9762\u8bd5\u6700\u7231\u95ee<\/td>\n<td align=\"left\">\u9ad8\u9891\u8003\u70b9\u6709\u54ea\u4e9b&#xff1f;<\/td>\n<td align=\"left\">\u89c1\u6587\u672b &#x1f3a4; \u5c0f\u8282<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>\u4e00\u3001\u6838\u5fc3\u77e5\u8bc6\u70b9<\/h4>\n<p>1. IoC\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>IoC&#xff08;Inversion of Control&#xff0c;\u63a7\u5236\u53cd\u8f6c&#xff09;\u662f\u4e00\u79cd\u8bbe\u8ba1\u539f\u5219&#xff0c;\u7528\u4e8e\u51cf\u5c11\u4ee3\u7801\u95f4\u7684\u76f4\u63a5\u4f9d\u8d56\u5173\u7cfb\u3002\u5176\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u5c06\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u4f9d\u8d56\u7ba1\u7406\u7b49\u63a7\u5236\u6743\u4ece\u4e1a\u52a1\u4ee3\u7801\u8f6c\u79fb\u5230\u5916\u90e8\u5bb9\u5668\u3002<\/p>\n<p>&#x1f4a1; \u901a\u4fd7\u7406\u89e3&#xff1a;\u4f20\u7edf\u7f16\u7a0b\u4e2d&#xff0c;\u8c03\u7528\u8005\u4e3b\u52a8\u521b\u5efa\u548c\u7ba1\u7406\u88ab\u8c03\u7528\u8005\u7684\u751f\u547d\u5468\u671f\u2014\u2014\u4f60\u9700\u8981\u4ec0\u4e48&#xff0c;\u81ea\u5df1new\u4e00\u4e2a\u3002IoC\u6a21\u5f0f\u4e0b&#xff0c;\u4f60\u53ea\u9700\u8981\u58f0\u660e&#034;\u6211\u9700\u8981\u4ec0\u4e48&#034;&#xff0c;\u5bb9\u5668\u4f1a\u5e2e\u4f60\u521b\u5efa\u597d\u5e76&#034;\u6ce8\u5165&#034;\u8fdb\u6765\u3002<\/p>\n<p>2. DI\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>DI&#xff08;Dependency Injection&#xff0c;\u4f9d\u8d56\u6ce8\u5165&#xff09;\u662fIoC\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u3002\u5bf9\u8c61\u53ea\u901a\u8fc7\u6784\u9020\u51fd\u6570\u53c2\u6570\u3001\u5de5\u5382\u65b9\u6cd5\u53c2\u6570\u6216\u5c5e\u6027\u6765\u5b9a\u4e49\u5b83\u4eec\u7684\u4f9d\u8d56\u9879&#xff0c;\u5bb9\u5668\u5728\u521b\u5efaBean\u65f6\u6ce8\u5165\u8fd9\u4e9b\u4f9d\u8d56\u3002<\/p>\n<p>&#x1f4a1; \u6838\u5fc3\u5173\u7cfb&#xff1a;IoC\u662f\u4e00\u79cd\u601d\u60f3&#xff0c;DI\u662f\u5b9e\u73b0\u8fd9\u79cd\u601d\u60f3\u7684\u6280\u672f\u624b\u6bb5\u3002<\/p>\n<p>3. IoC\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898&#xff1f;<\/p>\n<table>\n<tr>\u95ee\u9898\u4f20\u7edf\u65b9\u5f0fIoC\u65b9\u5f0f<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u8026\u5408\u5ea6\u9ad8<\/td>\n<td align=\"left\">\u7c7b\u5185\u90e8\u76f4\u63a5new\u4f9d\u8d56\u5bf9\u8c61&#xff0c;\u6362\u5b9e\u73b0\u8981\u6539\u4ee3\u7801<\/td>\n<td align=\"left\">\u4f9d\u8d56\u901a\u8fc7\u6784\u9020\u51fd\u6570\/Setter\u4f20\u5165&#xff0c;\u6362\u5b9e\u73b0\u4e0d\u6539\u4ee3\u7801<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u96be\u4ee5\u6d4b\u8bd5<\/td>\n<td align=\"left\">\u4f9d\u8d56\u786c\u7f16\u7801&#xff0c;\u65e0\u6cd5Mock<\/td>\n<td align=\"left\">\u4f9d\u8d56\u53ef\u66ff\u6362&#xff0c;\u5355\u5143\u6d4b\u8bd5\u5bb9\u6613<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u96be\u4ee5\u6269\u5c55<\/td>\n<td align=\"left\">\u65b0\u589e\u529f\u80fd\u8981\u6539\u5df2\u6709\u4ee3\u7801<\/td>\n<td align=\"left\">\u901a\u8fc7\u914d\u7f6e\/\u6ce8\u89e3\u6269\u5c55&#xff0c;\u7b26\u5408\u5f00\u95ed\u539f\u5219<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>4. IoC\u7684\u4e09\u5927\u4f18\u52bf<\/p>\n<table>\n<tr>\u4f18\u52bf\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u89e3\u8026\u6027<\/td>\n<td align=\"left\">\u5bf9\u8c61\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u901a\u8fc7\u5bb9\u5668\u914d\u7f6e\u800c\u975e\u786c\u7f16\u7801\u5b9e\u73b0<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u53ef\u6d4b\u8bd5\u6027<\/td>\n<td align=\"left\">\u4f9d\u8d56\u6ce8\u5165\u4f7f\u5f97\u5355\u5143\u6d4b\u8bd5\u53ef\u4ee5\u901a\u8fc7Mock\u5bf9\u8c61\u8f7b\u677e\u5b8c\u6210<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u53ef\u914d\u7f6e\u6027<\/td>\n<td align=\"left\">Bean\u7684\u521b\u5efa\u548c\u88c5\u914d\u8fc7\u7a0b\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u6216\u6ce8\u89e3\u7075\u6d3b\u8c03\u6574<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u4e8c\u3001\u901a\u4fd7\u8bb2\u89e3&#xff08;1\u5206\u949f\u5f00\u5fc3\u5b66&#xff09;<\/h4>\n<p>\u628aIoC\u5bb9\u5668\u60f3\u8c61\u6210&#034;\u667a\u80fd\u5de5\u5382 &#043; \u914d\u9001\u4e2d\u5fc3&#034;<\/p>\n<p>\u672c\u7cfb\u5217\u7b2c68\u7bc7\u8bb2\u8fc7&#xff0c;Servlet\u5bb9\u5668&#xff08;Tomcat&#xff09;\u662f&#034;\u540e\u53a8&#034;\u3002Spring IoC\u5bb9\u5668\u6bd4\u5b83\u66f4\u8fdb\u4e86\u4e00\u6b65\u2014\u2014\u5b83\u4e0d\u53ea\u662f&#034;\u540e\u53a8&#034;&#xff0c;\u800c\u662f\u6574\u6761\u4f9b\u5e94\u94fe\u7684\u667a\u80fd\u7ba1\u7406\u4e2d\u5fc3\u3002<\/p>\n<ul>\n<li>\u4f20\u7edf\u65b9\u5f0f&#xff08;\u81ea\u5df1new&#xff09; &#xff1a;\u4f60\u60f3\u505a\u4e00\u9053\u83dc&#xff0c;\u5f97\u81ea\u5df1\u79cd\u83dc\u3001\u81ea\u5df1\u517b\u732a\u3001\u81ea\u5df1\u78e8\u8c03\u6599\u2014\u2014\u6240\u6709\u4f9d\u8d56\u90fd\u5f97\u81ea\u5df1\u641e\u5b9a\u3002<\/li>\n<li>IoC\u65b9\u5f0f&#xff08;\u5bb9\u5668\u7ba1\u7406&#xff09; &#xff1a;\u4f60\u53ea\u9700\u8981\u544a\u8bc9\u5de5\u5382&#034;\u6211\u8981\u505a\u5bab\u4fdd\u9e21\u4e01&#034;&#xff0c;\u5de5\u5382\u81ea\u52a8\u628a\u9e21\u8089\u3001\u82b1\u751f\u3001\u5e72\u8fa3\u6912\u914d\u9f50\u9001\u5230\u4f60\u624b\u4e0a\u2014\u2014\u4f60\u53ea\u7ba1\u7092\u83dc\u3002<\/li>\n<\/ul>\n<p>\u4e24\u4e2a\u5bb9\u5668\u7684\u6bd4\u55bb&#xff1a;<\/p>\n<ul>\n<li>BeanFactory&#xff1a;\u5c0f\u533a\u697c\u4e0b\u7684\u81ea\u52a8\u552e\u8d27\u673a\u2014\u2014\u4f60\u8981\u4ec0\u4e48&#xff0c;\u6295\u5e01\u624d\u51fa\u8d27&#xff08;\u61d2\u52a0\u8f7d&#xff09;&#xff0c;\u529f\u80fd\u5355\u4e00\u3002<\/li>\n<li>ApplicationContext&#xff1a;\u5927\u578b\u4ed3\u50a8\u8d85\u5e02\u2014\u2014\u4e00\u5f00\u95e8\u5c31\u628a\u6240\u6709\u8d27\u54c1\u90fd\u6446\u597d&#xff08;\u9884\u52a0\u8f7d&#xff09;&#xff0c;\u8fd8\u63d0\u4f9b\u63a8\u8f66\u3001\u5bfc\u8d2d\u3001\u9000\u6362\u8d27\u7b49\u5168\u5957\u670d\u52a1&#xff08;\u4e8b\u4ef6\u3001\u56fd\u9645\u5316\u3001AOP\u7b49&#xff09;\u3002<\/li>\n<\/ul>\n<h4>\u4e09\u3001Spring IoC\u5bb9\u5668\u4f53\u7cfb<\/h4>\n<h5>3.1 \u5bb9\u5668\u5c42\u7ea7\u5173\u7cfb<\/h5>\n<p>Spring\u7684IoC\u5bb9\u5668\u4ee5 BeanFactory \u4e3a\u9876\u5c42\u63a5\u53e3&#xff0c;ApplicationContext \u662f\u5176\u5b50\u63a5\u53e3&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813224855-6a7e49d78c6d4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>org.springframework.beans \u548c org.springframework.context \u5305\u662fSpring Framework IoC\u5bb9\u5668\u7684\u57fa\u7840\u3002<\/p>\n<h5>3.2 BeanFactory vs ApplicationContext<\/h5>\n<p>\u8fd9\u662fSpring\u9762\u8bd5100%\u4f1a\u95ee\u7684\u5bf9\u6bd4\u9898\u3002<\/p>\n<table>\n<tr>\u5bf9\u6bd4\u7ef4\u5ea6BeanFactoryApplicationContext<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u5b98\u65b9\u5b9a\u4f4d<\/td>\n<td align=\"left\">\u6700\u57fa\u7840\u7684IoC\u5bb9\u5668\u63a5\u53e3&#xff0c;\u5b9a\u4e49Bean\u7ba1\u7406\u7684\u6838\u5fc3\u89c4\u8303<\/td>\n<td align=\"left\">BeanFactory\u7684\u5b50\u63a5\u53e3&#xff0c;\u589e\u52a0\u4e86\u4f01\u4e1a\u7ea7\u529f\u80fd<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u52a0\u8f7d\u7b56\u7565<\/td>\n<td align=\"left\">\u61d2\u52a0\u8f7d\u2014\u2014\u8c03\u7528getBean()\u65f6\u624d\u521b\u5efa\u5b9e\u4f8b<\/td>\n<td align=\"left\">\u9884\u52a0\u8f7d\u2014\u2014\u542f\u52a8\u65f6\u4e00\u6b21\u6027\u521b\u5efa\u6240\u6709\u5355\u4f8bBean<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6838\u5fc3\u529f\u80fd<\/td>\n<td align=\"left\">\u53ea\u63d0\u4f9bgetBean()\u7b49\u57fa\u7840\u529f\u80fd<\/td>\n<td align=\"left\">\u7ee7\u627fBeanFactory\u5168\u90e8\u529f\u80fd &#043; 10\u5927\u6269\u5c55\u529f\u80fd<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5b9e\u9645\u4f7f\u7528<\/td>\n<td align=\"left\">\u51e0\u4e4e\u89c1\u4e0d\u5230<\/td>\n<td align=\"left\">\u6bcf\u5929\u90fd\u7528\u2014\u2014SpringApplication.run(&#8230;)\u8fd4\u56de\u7684\u5c31\u662f\u5b83<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5e38\u7528\u5b9e\u73b0<\/td>\n<td align=\"left\">DefaultListableBeanFactory<\/td>\n<td align=\"left\">AnnotationConfigApplicationContext\u3001ClassPathXmlApplicationContext<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>ApplicationContext\u6bd4BeanFactory\u591a\u51fa\u7684\u6838\u5fc3\u529f\u80fd&#xff1a;<\/p>\n<table>\n<tr>\u529f\u80fd\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u4e8b\u4ef6\u53d1\u5e03\u4e0e\u76d1\u542c<\/td>\n<td align=\"left\">ApplicationEvent &#043; &#064;EventListener<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u56fd\u9645\u5316&#xff08;i18n&#xff09;<\/td>\n<td align=\"left\">MessageSource\u652f\u6301\u591a\u8bed\u8a00<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u8d44\u6e90\u52a0\u8f7d<\/td>\n<td align=\"left\">ResourceLoader\u652f\u6301classpath:\u3001file:\u7b49<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u73af\u5883\u62bd\u8c61<\/td>\n<td align=\"left\">Environment &#043; &#064;Profile\u652f\u6301\u591a\u73af\u5883\u914d\u7f6e<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">AOP\u81ea\u52a8\u4ee3\u7406<\/td>\n<td align=\"left\">\u81ea\u52a8\u8bc6\u522b&#064;Aspect\u5e76\u7ec7\u5165&#xff0c;&#064;Transactional\u76f4\u63a5\u751f\u6548<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Web\u5e94\u7528\u652f\u6301<\/td>\n<td align=\"left\">WebApplicationContext<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4a1; \u8bb0\u5fc6\u53e3\u8bc0&#xff1a;BeanFactory\u662f&#034;\u57fa\u7840\u6b3e&#034;&#xff08;\u591f\u7528\u4f46\u7b80\u964b&#xff09;&#xff0c;ApplicationContext\u662f&#034;\u65d7\u8230\u6b3e&#034;&#xff08;\u529f\u80fd\u5168\u3001\u4f53\u9a8c\u597d&#xff09; \u3002\u5b9e\u9645\u9879\u76ee100%\u7528ApplicationContext\u3002<\/p>\n<h5>3.3 Bean\u662f\u4ec0\u4e48&#xff1f;<\/h5>\n<p>\u5728Spring\u4e2d&#xff0c;\u6784\u6210\u5e94\u7528\u7a0b\u5e8f\u9aa8\u67b6\u5e76\u7531Spring IoC\u5bb9\u5668\u7ba1\u7406\u7684\u5bf9\u8c61\u79f0\u4e3aBean\u3002Bean\u662f\u7531Spring IoC\u5bb9\u5668\u5b9e\u4f8b\u5316\u3001\u7ec4\u88c5\u548c\u7ba1\u7406\u7684\u5bf9\u8c61\u3002<\/p>\n<p>&#x1f4a1; \u672c\u8d28&#xff1a;Bean\u5c31\u662f\u4e00\u4e2a\u666e\u901a\u7684Java\u5bf9\u8c61&#xff0c;\u552f\u4e00\u7279\u6b8a\u4e4b\u5904\u5728\u4e8e\u2014\u2014\u5b83\u7531Spring\u5bb9\u5668\u7ba1\u7406&#xff0c;\u800c\u4e0d\u662f\u4f60\u81ea\u5df1new\u51fa\u6765\u7684\u3002<\/p>\n<h4>\u56db\u3001Bean\u751f\u547d\u5468\u671f&#xff08;5\u9636\u6bb5&#xff09;<\/h4>\n<p>Bean\u7684\u751f\u547d\u5468\u671f\u662fSpring\u9762\u8bd5\u7684\u5fc5\u8003\u9879&#xff0c;\u9700\u8981\u638c\u63e1\u4ee5\u4e0b\u6838\u5fc3\u9636\u6bb5&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813224855-6a7e49d7b3b38.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u521d\u59cb\u5316\u9636\u6bb5\u8be6\u89e3&#xff08;\u8fd9\u662f\u751f\u547d\u5468\u671f\u4e2d\u6700\u590d\u6742\u7684\u9636\u6bb5&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u6b65\u9aa4\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u2460 Aware\u63a5\u53e3\u56de\u8c03<\/td>\n<td align=\"left\">BeanNameAware\u3001BeanFactoryAware\u7b49<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u2461 BeanPostProcessor\u524d\u7f6e\u5904\u7406<\/td>\n<td align=\"left\">\u521d\u59cb\u5316\u524d\u7684\u62e6\u622a<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u2462 InitializingBean.afterPropertiesSet()<\/td>\n<td align=\"left\">\u63a5\u53e3\u65b9\u5f0f\u521d\u59cb\u5316<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u2463 \u81ea\u5b9a\u4e49init-method<\/td>\n<td align=\"left\">XML\u6216\u6ce8\u89e3\u6307\u5b9a\u7684\u521d\u59cb\u5316\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u2464 BeanPostProcessor\u540e\u7f6e\u5904\u7406<\/td>\n<td align=\"left\">\u521d\u59cb\u5316\u540e\u7684\u62e6\u622a&#xff0c;AOP\u4ee3\u7406\u5728\u6b64\u5b8c\u6210<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u4e94\u3001\u4e09\u79cdBean\u914d\u7f6e\u65b9\u5f0f<\/h4>\n<p>\u5bb9\u5668\u901a\u8fc7\u8bfb\u53d6\u914d\u7f6e\u5143\u6570\u636e\u6765\u83b7\u53d6\u6307\u4ee4\u2014\u2014\u544a\u8bc9\u5b83\u8981\u5b9e\u4f8b\u5316\u54ea\u4e9b\u5bf9\u8c61\u3001\u5982\u4f55\u88c5\u914d\u5b83\u4eec\u3002\u914d\u7f6e\u5143\u6570\u636e\u53ef\u4ee5\u7528\u4e09\u79cd\u65b9\u5f0f\u8868\u8fbe&#xff1a;<\/p>\n<h5>5.1 XML\u914d\u7f6e&#xff08;\u4f20\u7edf\u65b9\u5f0f&#xff09;<\/h5>\n<p><span class=\"token comment\">&lt;!&#8211; applicationContext.xml &#8211;&gt;<\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>beans<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>bean<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>userService<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>com.example.UserServiceImpl<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>property<\/span> <span class=\"token attr-name\">name<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>userDao<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">ref<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>userDao<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">\/&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>bean<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>bean<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>userDao<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>com.example.UserDaoImpl<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">\/&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>beans<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u52a0\u8f7dXML\u914d\u7f6e<\/span><br \/>\n<span class=\"token class-name\">ApplicationContext<\/span> ctx <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ClassPathXmlApplicationContext<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;applicationContext.xml&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\">UserService<\/span> service <span class=\"token operator\">&#061;<\/span> ctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">getBean<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;userService&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">UserService<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>5.2 \u6ce8\u89e3\u914d\u7f6e&#xff08;\u4e3b\u6d41\u65b9\u5f0f&#xff09;<\/h5>\n<p><span class=\"token annotation punctuation\">&#064;Service<\/span>  <span class=\"token comment\">\/\/ \u58f0\u660e\u4e3a\u4e1a\u52a1\u5c42Bean<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">UserServiceImpl<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">UserService<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Autowired<\/span>  <span class=\"token comment\">\/\/ \u81ea\u52a8\u6ce8\u5165\u4f9d\u8d56<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">UserDao<\/span> userDao<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token annotation punctuation\">&#064;Repository<\/span>  <span class=\"token comment\">\/\/ \u58f0\u660e\u4e3a\u6570\u636e\u8bbf\u95ee\u5c42Bean<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">UserDaoImpl<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">UserDao<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6570\u636e\u8bbf\u95ee\u903b\u8f91<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u542f\u52a8\u5bb9\u5668&#xff08;Spring Boot\u81ea\u52a8\u5b8c\u6210&#xff09;<\/span><br \/>\n<span class=\"token class-name\">ApplicationContext<\/span> ctx <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">AnnotationConfigApplicationContext<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;com.example&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>&#x1f4a1; \u6ce8\u89e3\u542b\u4e49&#xff1a;&#064;Component \u662f\u901a\u7528\u6ce8\u89e3&#xff0c;&#064;Service\u3001&#064;Repository\u3001&#064;Controller \u662f\u5176\u7279\u5316\u7248\u672c&#xff0c;\u5206\u522b\u7528\u4e8e\u4e1a\u52a1\u5c42\u3001\u6570\u636e\u5c42\u548c\u63a7\u5236\u5c42\u3002<\/p>\n<h5>5.3 Java\u914d\u7f6e&#xff08;&#064;Configuration &#043; &#064;Bean&#xff09;<\/h5>\n<p><span class=\"token annotation punctuation\">&#064;Configuration<\/span>  <span class=\"token comment\">\/\/ \u58f0\u660e\u8fd9\u662f\u4e00\u4e2a\u914d\u7f6e\u7c7b<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">AppConfig<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span>  <span class=\"token comment\">\/\/ \u65b9\u6cd5\u8fd4\u56de\u503c\u4f1a\u88ab\u6ce8\u518c\u4e3aSpring\u5bb9\u5668\u4e2d\u7684Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">UserService<\/span> <span class=\"token function\">userService<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">UserDao<\/span> userDao<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">UserServiceImpl<\/span><span class=\"token punctuation\">(<\/span>userDao<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">UserDao<\/span> <span class=\"token function\">userDao<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">UserDaoImpl<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u52a0\u8f7dJava\u914d\u7f6e<\/span><br \/>\n<span class=\"token class-name\">ApplicationContext<\/span> ctx <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">AnnotationConfigApplicationContext<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">AppConfig<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>&#x1f4a1; &#064;Configuration\u539f\u7406&#xff1a;\u914d\u7f6e\u7c7b\u4f1a\u7ecf\u8fc7ConfigurationClassPostProcessor&#xff08;\u540e\u7f6e\u5904\u7406\u5668&#xff09;\u5904\u7406&#xff0c;\u89e3\u6790\u6240\u6709&#064;Bean\u65b9\u6cd5\u5e76\u8f6c\u6362\u4e3aBean\u5b9a\u4e49\u3002&#064;Configuration\u7c7b\u672c\u8eab\u4e5f\u4f1a\u88ab\u6ce8\u518c\u4e3a\u5bb9\u5668\u4e2d\u7684\u4e00\u4e2aBean\u3002<\/p>\n<h4>\u516d\u3001\u907f\u5751\u8981\u70b9<\/h4>\n<table>\n<tr>\u9519\u8bef\/\u8bef\u533a\u540e\u679c\u6b63\u786e\u505a\u6cd5<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u6df7\u6dc6IoC\u548cDI\u7684\u6982\u5ff5<\/td>\n<td align=\"left\">\u9762\u8bd5\u7b54\u975e\u6240\u95ee<\/td>\n<td align=\"left\">IoC\u662f\u601d\u60f3&#xff0c;DI\u662f\u5b9e\u73b0\u65b9\u5f0f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u8ba4\u4e3anew\u51fa\u6765\u7684\u5bf9\u8c61\u4e5f\u662fBean<\/td>\n<td align=\"left\">\u5bb9\u5668\u65e0\u6cd5\u7ba1\u7406&#xff0c;\u4f9d\u8d56\u6ce8\u5165\u5931\u6548<\/td>\n<td align=\"left\">\u53ea\u6709\u5bb9\u5668\u521b\u5efa\u548c\u7ba1\u7406\u7684\u5bf9\u8c61\u624d\u662fBean<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u8bef\u4ee5\u4e3a\u9879\u76ee\u7528\u7684\u662fBeanFactory<\/td>\n<td align=\"left\">\u5bf9\u5bb9\u5668\u80fd\u529b\u7406\u89e3\u6709\u504f\u5dee<\/td>\n<td align=\"left\">\u5b9e\u9645\u9879\u76ee100%\u7528ApplicationContext<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u4e0d\u77e5\u9053&#064;Configuration\u548c&#064;Component\u7684\u533a\u522b<\/td>\n<td align=\"left\">\u914d\u7f6e\u7c7b\u88ab\u4ee3\u7406&#xff0c;\u884c\u4e3a\u5f02\u5e38<\/td>\n<td align=\"left\">&#064;Configuration\u662f\u914d\u7f6e\u7c7b&#xff08;Full\u6a21\u5f0f&#xff09;&#xff0c;&#064;Component\u662f\u666e\u901a\u7ec4\u4ef6<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5728Bean\u7684\u6784\u9020\u51fd\u6570\u4e2d\u505a\u8017\u65f6\u64cd\u4f5c<\/td>\n<td align=\"left\">\u5bb9\u5668\u542f\u52a8\u53d8\u6162<\/td>\n<td align=\"left\">\u8017\u65f6\u64cd\u4f5c\u653e\u5230&#064;PostConstruct\u6216afterPropertiesSet\u4e2d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u4e03\u3001\u9762\u8bd5\u9ad8\u9891\u8003\u70b9<\/h4>\n<p>Q1&#xff1a;IoC\u548cDI\u662f\u4ec0\u4e48\u5173\u7cfb&#xff1f;<\/p>\n<p>IoC&#xff08;\u63a7\u5236\u53cd\u8f6c&#xff09;\u662f\u4e00\u79cd\u8bbe\u8ba1\u601d\u60f3\u2014\u2014\u5c06\u5bf9\u8c61\u7684\u521b\u5efa\u548c\u4f9d\u8d56\u7ba1\u7406\u7684\u63a7\u5236\u6743\u4ece\u4ee3\u7801\u8f6c\u79fb\u5230\u5bb9\u5668\u3002DI&#xff08;\u4f9d\u8d56\u6ce8\u5165&#xff09;\u662fIoC\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u2014\u2014\u5bf9\u8c61\u901a\u8fc7\u6784\u9020\u51fd\u6570\u53c2\u6570\u3001\u5de5\u5382\u65b9\u6cd5\u53c2\u6570\u6216\u5c5e\u6027\u6765\u5b9a\u4e49\u4f9d\u8d56&#xff0c;\u5bb9\u5668\u5728\u521b\u5efaBean\u65f6\u6ce8\u5165\u8fd9\u4e9b\u4f9d\u8d56\u3002IoC\u662f&#034;\u7406\u5ff5&#034;&#xff0c;DI\u662f&#034;\u505a\u6cd5&#034; \u3002<\/p>\n<p>Q2&#xff1a;BeanFactory\u548cApplicationContext\u7684\u533a\u522b&#xff1f;<\/p>\n<p>BeanFactory\u662fSpring\u6700\u57fa\u7840\u7684IoC\u5bb9\u5668\u63a5\u53e3&#xff0c;\u91c7\u7528\u61d2\u52a0\u8f7d\u7b56\u7565&#xff0c;\u53ea\u63d0\u4f9bgetBean()\u7b49\u57fa\u7840\u529f\u80fd\u3002ApplicationContext\u662fBeanFactory\u7684\u5b50\u63a5\u53e3&#xff0c;\u91c7\u7528\u9884\u52a0\u8f7d\u7b56\u7565\u2014\u2014\u542f\u52a8\u65f6\u4e00\u6b21\u6027\u521b\u5efa\u6240\u6709\u5355\u4f8bBean&#xff0c;\u8fd8\u989d\u5916\u63d0\u4f9b\u4e86\u4e8b\u4ef6\u53d1\u5e03\u3001\u56fd\u9645\u5316\u3001\u8d44\u6e90\u52a0\u8f7d\u3001AOP\u96c6\u6210\u7b49\u4f01\u4e1a\u7ea7\u529f\u80fd\u3002\u5b9e\u9645\u9879\u76ee100%\u7528ApplicationContext\u3002<\/p>\n<p>Q3&#xff1a;Spring Bean\u7684\u751f\u547d\u5468\u671f\u6709\u54ea\u4e9b\u9636\u6bb5&#xff1f;<\/p>\n<p>\u4e94\u4e2a\u9636\u6bb5&#xff1a;\u2460\u5b9e\u4f8b\u5316\u2014\u2014\u5bb9\u5668\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u6784\u9020\u51fd\u6570\u521b\u5efa\u5b9e\u4f8b&#xff1b;\u2461\u5c5e\u6027\u586b\u5145\u2014\u2014\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u8bbe\u7f6e\u5c5e\u6027\u503c&#xff1b;\u2462\u521d\u59cb\u5316\u2014\u2014\u6267\u884cAware\u56de\u8c03\u3001BeanPostProcessor\u524d\u7f6e\u5904\u7406\u3001afterPropertiesSet\u3001\u81ea\u5b9a\u4e49init-method\u3001BeanPostProcessor\u540e\u7f6e\u5904\u7406&#xff1b;\u2463\u4f7f\u7528\u2014\u2014Bean\u88ab\u5e94\u7528\u7a0b\u5e8f\u8c03\u7528&#xff1b;\u2464\u9500\u6bc1\u2014\u2014\u5bb9\u5668\u5173\u95ed\u65f6\u6309\u76f8\u53cd\u987a\u5e8f\u89e6\u53d1\u9500\u6bc1\u903b\u8f91\u3002<\/p>\n<p>Q4&#xff1a;&#064;Configuration\u548c&#064;Bean\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>&#064;Configuration\u6807\u8bb0\u5728\u7c7b\u4e0a&#xff0c;\u58f0\u660e\u8fd9\u662f\u4e00\u4e2a\u914d\u7f6e\u7c7b&#xff0c;\u76f8\u5f53\u4e8eXML\u914d\u7f6e\u6587\u4ef6\u3002&#064;Bean\u6807\u8bb0\u5728\u914d\u7f6e\u7c7b\u7684\u65b9\u6cd5\u4e0a&#xff0c;\u6307\u793a\u8be5\u65b9\u6cd5\u8fd4\u56de\u7684\u5bf9\u8c61\u5e94\u8be5\u88ab\u6ce8\u518c\u4e3aSpring\u5bb9\u5668\u4e2d\u7684Bean\u3002\u914d\u7f6e\u7c7b\u4f1a\u7ecf\u8fc7ConfigurationClassPostProcessor\u5904\u7406&#xff0c;\u5c06&#064;Bean\u65b9\u6cd5\u8f6c\u6362\u4e3aBean\u5b9a\u4e49\u3002<\/p>\n<p>Q5&#xff1a;Spring\u652f\u6301\u54ea\u51e0\u79cdBean\u914d\u7f6e\u65b9\u5f0f&#xff1f;<\/p>\n<p>\u4e09\u79cd&#xff1a;\u2460XML\u914d\u7f6e\u2014\u2014\u4f20\u7edf\u7684&lt;bean&gt;\u6807\u7b7e\u65b9\u5f0f&#xff1b;\u2461\u6ce8\u89e3\u914d\u7f6e\u2014\u2014\u901a\u8fc7&#064;Component\u3001&#064;Service\u3001&#064;Autowired\u7b49\u6ce8\u89e3&#xff1b;\u2462Java\u914d\u7f6e\u2014\u2014\u901a\u8fc7&#064;Configuration &#043; &#064;Bean\u3002\u73b0\u4ee3Spring Boot\u9879\u76ee\u4ee5\u6ce8\u89e3\u914d\u7f6e\u548cJava\u914d\u7f6e\u4e3a\u4e3b\u3002<\/p>\n<h4>&#x1f3a4; \u9762\u8bd5\u5b98\u8ffd\u95ee\u9677\u9631&#xff08;\u52a0\u5206\u9898&#xff09;<\/h4>\n<p>\u8ffd\u95ee1&#xff1a;\u201c&#064;Configuration\u6807\u6ce8\u7684\u7c7b\u548c&#064;Component\u6807\u6ce8\u7684\u7c7b\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;\u201d<\/p>\n<p>&#x1f449; &#064;Configuration\u7c7b\u4f1a\u88abSpring\u52a8\u6001\u4ee3\u7406&#xff0c;\u4fdd\u8bc1\u5176\u4e2d&#064;Bean\u65b9\u6cd5\u8c03\u7528\u65f6\u8fd4\u56de\u7684\u662f\u5bb9\u5668\u4e2d\u5df2\u5b58\u5728\u7684Bean\u5b9e\u4f8b&#xff08;\u4fdd\u8bc1\u5355\u4f8b&#xff09;\u3002\u800c&#064;Component\u6807\u6ce8\u7684\u666e\u901a\u7c7b\u4e0d\u4f1a\u88ab\u4ee3\u7406\u3002\u7b80\u5355\u8bf4&#xff1a;&#064;Configuration\u662f&#034;Full\u6a21\u5f0f&#034;&#xff08;Bean\u4e4b\u95f4\u8c03\u7528\u8d70\u4ee3\u7406&#xff09;&#xff0c;&#064;Component\u662f&#034;Lite\u6a21\u5f0f&#034;&#xff08;\u4e0d\u8d70\u4ee3\u7406&#xff09; \u3002<\/p>\n<p>\u8ffd\u95ee2&#xff1a;\u201cApplicationContext\u542f\u52a8\u65f6\u505a\u4e86\u4ec0\u4e48\u4e8b&#xff1f;\u80fd\u7b80\u5355\u8bf4\u4e0b\u6d41\u7a0b\u5417&#xff1f;\u201d<\/p>\n<p>&#x1f449; \u6838\u5fc3\u662frefresh()\u65b9\u6cd5\u3002\u4e3b\u8981\u6b65\u9aa4&#xff1a;\u2460\u521b\u5efa\u5e76\u51c6\u5907BeanFactory&#xff1b;\u2461\u8bfb\u53d6\u914d\u7f6e\u5143\u6570\u636e&#xff08;XML\/\u6ce8\u89e3\/Java\u914d\u7f6e&#xff09;&#xff0c;\u751f\u6210BeanDefinition&#xff1b;\u2462\u6ce8\u518cBeanPostProcessor&#xff1b;\u2463\u521d\u59cb\u5316\u6240\u6709\u975e\u61d2\u52a0\u8f7d\u7684\u5355\u4f8bBean&#xff1b;\u2464\u53d1\u5e03\u4e0a\u4e0b\u6587\u5c31\u7eea\u4e8b\u4ef6\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48ApplicationContext\u542f\u52a8\u6bd4BeanFactory\u6162\u2014\u2014\u5b83\u628a\u6d3b\u90fd\u63d0\u524d\u5e72\u5b8c\u4e86\u3002<\/p>\n<h4>\u516b\u3001\u7ec3\u4e60\u9898<\/h4>\n<li>\n<p>\u7b80\u7b54\u9898&#xff1a;\u8bf7\u7528\u81ea\u5df1\u7684\u8bdd\u89e3\u91caIoC\u548cDI\u7684\u5173\u7cfb\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u9898&#xff1a;\u4f7f\u7528&#064;Configuration &#043; &#064;Bean\u65b9\u5f0f&#xff0c;\u914d\u7f6e\u4e00\u4e2aDataSource Bean\u548c\u4e00\u4e2aUserDao Bean&#xff0c;UserDao\u4f9d\u8d56DataSource\u3002<\/p>\n<\/li>\n<li>\n<p>\u5206\u6790\u9898&#xff1a;\u67d0Spring Boot\u9879\u76ee\u542f\u52a8\u975e\u5e38\u6162&#xff0c;\u7ecf\u6392\u67e5\u53d1\u73b0\u542f\u52a8\u65f6\u521b\u5efa\u4e86\u5927\u91cfBean\u3002\u8bf7\u5206\u6790\u53ef\u80fd\u7684\u539f\u56e0&#xff0c;\u5e76\u7ed9\u51fa\u4f18\u5316\u5efa\u8bae\u3002<\/p>\n<\/li>\n<h3>&#x1f4ca; \u4f60\u7684\u5b66\u4e60\u8fdb\u5ea6<\/h3>\n<ul>\n<li>\u5f53\u524d&#xff1a;\u7b2c73\u7bc7 \/ \u5171108\u7bc7 \u00b7 \u8fdb\u9636\u7bc7&#xff1a;Spring\u5168\u5bb6\u6876&#xff08;\u7b2c73~82\u7bc7&#xff09;<\/li>\n<li>\u2705 \u5df2\u5b8c\u6210&#xff1a;\u57fa\u7840\u7bc744\u7bc7 &#043; \u7b2c45~73\u7bc7<\/li>\n<li>&#x1f4d6; \u6b63\u5728\u5b66&#xff1a;\u7b2c73\u7bc7<\/li>\n<li>\u23f3 \u5f85\u5b66\u4e60&#xff1a;\u7b2c74~108\u7bc7<\/li>\n<\/ul>\n<p>&#x1f449; &#x1f4da; \u5b8c\u6574\u76ee\u5f55 &amp; \u5b66\u4e60\u6307\u5357 | &#x1f525; \u8ba2\u9605\u672c\u4e13\u680f&#xff0c;\u4e0d\u9519\u8fc7\u6bcf\u4e00\u7bc7<\/p>\n<h3>&#x1f449; \u4e0b\u4e00\u7bc7\u6587\u7ae0\u9884\u544a<\/h3>\n<p>&#x1f680; \u4e0b\u4e00\u7bc7&#xff1a;\u300a\u7b2c74\u7bc7&#xff1a;Bean\u751f\u547d\u5468\u671f\u300b<\/p>\n<p>\u5185\u5bb9\u7b80\u4ecb&#xff1a;Bean\u751f\u547d\u5468\u671f\u5b8c\u657415\u6b65\u8be6\u89e3\u3001BeanPostProcessor\u539f\u7406\u3001InitializingBean\u4e0e&#064;PostConstruct\u6267\u884c\u987a\u5e8f\u3001\u9500\u6bc1\u6d41\u7a0b\u3001\u6269\u5c55\u70b9\u5b9e\u6218\u3002<\/p>\n<p>&#x1f449; Spring\u5168\u5bb6\u6876\u4e13\u9898\u6301\u7eed\u63a8\u8fdb&#xff0c;\u6df1\u5165Bean\u751f\u547d\u5468\u671f&#xff01;<\/p>\n<p>&#x1f4cc; \u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def | \u4ece\u5165\u95e8\u5230\u4e0a\u5c97\u5c31\u4e1a\u300b \u6bcf\u5929\u4e00\u7bc7&#xff0c;\u5efa\u8bae\u6536\u85cf &#043; \u5173\u6ce8&#xff0c;\u4e00\u8d77100\u5929\u62ffoffer&#xff01; &#x1f449; \u70b9\u51fb\u5173\u6ce8\u6211&#xff0c;\u66f4\u65b0\u540e\u7b2c\u4e00\u65f6\u95f4\u6536\u5230\u63a8\u9001&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c73\u7bc7&#xff1a;Spring IoC\u5bb9\u5668&#xff08;2026\u7248&#xff09; &#x1f4cc; \u7cfb\u5217\u5bfc\u822a&#xff1a;\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u5b8c\u6574\u76ee\u5f55 | \u2b05\ufe0f \u4e0a\u4e00\u7bc7&#xff1a;\u7b2c72\u7bc7&#xff1a;JavaWeb\u9762\u8bd5\u9ad8\u9891\u9898 | \u27a1\ufe0f \u4e0b\u4e00\u7bc7&#xff1a;\u7b2c74\u7bc7&#xff1a;Bean\u751f\u547d\u5468\u671f&#xff08;\u5f85\u53d1\u5e03&#xff09; &#x1f5fa;\ufe0f \u672c\u6587\u9605\u8bfb\u5730\u56fe&#xff08;3 \u5206\u949f\u901f\u89c8&#xff09; \u7b2c72\u7bc7\u5b8c\u6210\u4e86JavaWeb<\/p>\n","protected":false},"author":2,"featured_media":94270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10797,10187,5220,99,101,3893],"topic":[],"class_list":["post-94272","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-beanfactory","tag-codingplan","tag-ioc","tag-java","tag-spring","tag-3893"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/94272.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c73\u7bc7&#xff1a;Spring IoC\u5bb9\u5668&#xff08;2026\u7248&#xff09; &#x1f4cc; \u7cfb\u5217\u5bfc\u822a&#xff1a;\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u5b8c\u6574\u76ee\u5f55 | \u2b05\ufe0f \u4e0a\u4e00\u7bc7&#xff1a;\u7b2c72\u7bc7&#xff1a;JavaWeb\u9762\u8bd5\u9ad8\u9891\u9898 | \u27a1\ufe0f \u4e0b\u4e00\u7bc7&#xff1a;\u7b2c74\u7bc7&#xff1a;Bean\u751f\u547d\u5468\u671f&#xff08;\u5f85\u53d1\u5e03&#xff09; &#x1f5fa;\ufe0f \u672c\u6587\u9605\u8bfb\u5730\u56fe&#xff08;3 \u5206\u949f\u901f\u89c8&#xff09; \u7b2c72\u7bc7\u5b8c\u6210\u4e86JavaWeb\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/94272.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-13T22:48:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813224855-6a7e49d78c6d4.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94272.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/94272.html\",\"name\":\"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-13T22:48:56+00:00\",\"dateModified\":\"2026-08-13T22:48:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/94272.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/94272.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/94272.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/94272.html","og_locale":"zh_CN","og_type":"article","og_title":"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c73\u7bc7&#xff1a;Spring IoC\u5bb9\u5668&#xff08;2026\u7248&#xff09; &#x1f4cc; \u7cfb\u5217\u5bfc\u822a&#xff1a;\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u5b8c\u6574\u76ee\u5f55 | \u2b05\ufe0f \u4e0a\u4e00\u7bc7&#xff1a;\u7b2c72\u7bc7&#xff1a;JavaWeb\u9762\u8bd5\u9ad8\u9891\u9898 | \u27a1\ufe0f \u4e0b\u4e00\u7bc7&#xff1a;\u7b2c74\u7bc7&#xff1a;Bean\u751f\u547d\u5468\u671f&#xff08;\u5f85\u53d1\u5e03&#xff09; &#x1f5fa;\ufe0f \u672c\u6587\u9605\u8bfb\u5730\u56fe&#xff08;3 \u5206\u949f\u901f\u89c8&#xff09; \u7b2c72\u7bc7\u5b8c\u6210\u4e86JavaWeb","og_url":"https:\/\/www.wsisp.com\/helps\/94272.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-13T22:48:56+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813224855-6a7e49d78c6d4.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/94272.html","url":"https:\/\/www.wsisp.com\/helps\/94272.html","name":"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-13T22:48:56+00:00","dateModified":"2026-08-13T22:48:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/94272.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/94272.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/94272.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u300aJava 100 \u5929\u8fdb\u9636\u4e4b\u8def\u300b\u7b2c73\u7bc7\uff1aSpring IoC\u5bb9\u5668\uff082026\u7248\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/94272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=94272"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/94272\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/94270"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=94272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=94272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=94272"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=94272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}