{"id":1894,"date":"2026-04-16T17:02:11","date_gmt":"2026-04-16T09:02:11","guid":{"rendered":"http:\/\/www.spiceandwolf.com.cn\/?p=1894"},"modified":"2026-04-23T19:29:53","modified_gmt":"2026-04-23T11:29:53","slug":"spring-auto-configuration","status":"publish","type":"post","link":"http:\/\/www.spiceandwolf.com.cn\/index.php\/spring-auto-configuration\/","title":{"rendered":"Spring\u81ea\u52a8\u88c5\u914d\u8be6\u89e3"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u5b9a\u4e49<\/h3>\n\n\n\n<p>Spring boot\u81ea\u52a8\u88c5\u914d\u6307\u7684\u662f\u901a\u8fc7\u7ea6\u5b9a\u4f18\u4e8e\u914d\u7f6e\u7684\u601d\u60f3\uff0c\u81ea\u52a8\u5c06\u7b2c\u4e09\u65b9\u5e93\u6216\u5e38\u7528\u7ec4\u4ef6\u7684bean\u52a0\u8f7d\u5230spring\u5bb9\u5668\u4e2d\uff0c\u4ece\u800c\u5927\u5e45\u51cf\u5c11\u914d\u7f6e\u5de5\u4f5c\u7684\u673a\u5236\uff0c\u662fspring boot\u7684\u6838\u5fc3\u7279\u6027\u4e4b\u4e00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u81ea\u52a8\u88c5\u914d\u7684\u4f18\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b80\u5316\u914d\u7f6e\u3002\u4f20\u7edf\u7684\u624b\u52a8\u88c5\u914d\u65b9\u5f0f\u6709xml\u548c\u6ce8\u89e3\u65b9\u5f0f\uff0c\u9700\u8981\u624b\u52a8\u521b\u5efaxml\u6587\u4ef6\u6216\u8005java\u7c7b\u6765\u5b8c\u6210bean\u7684\u76f8\u5173\u914d\u7f6e\uff0c\u4f46\u662fspring boot\u9075\u4ece\u7ea6\u5b9a\u4f18\u4e8e\u914d\u7f6e\u7684\u601d\u60f3\uff0c\u5c06\u5927\u91cf\u7684bean\u914d\u7f6e\u548c\u6ce8\u5165\u7684\u76f8\u5173\u903b\u8f91\u96c6\u6210\u5230starter\u542f\u52a8\u7c7b\u4e2d\uff0c\u51cf\u5c11\u4e86\u5197\u4f59\u914d\u7f6e\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li>\u5f00\u7bb1\u5373\u7528\u3002\u901a\u8fc7\u6781\u5c11\u7684\u914d\u7f6e\uff0c\u5c31\u80fd\u8ba9\u5e94\u7528\u5feb\u901f\u90e8\u7f72\u5e76\u6295\u5165\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>\u5b9e\u73b0\u4e86\u7248\u672c\u63a7\u5236\u548c\u4f9d\u8d56\u7ba1\u7406\u3002\u81ea\u52a8\u88c5\u914d\u7279\u6027\u5c06\u7248\u672c\u517c\u5bb9\u4ee3\u7801\u548c\u4f9d\u8d56\u63a7\u5236\u7684\u4ee3\u7801\u903b\u8f91\u4ea4\u7531\u542f\u52a8\u7c7b\u5b9e\u73b0\uff0c\u7b80\u5316\u4e86\u5f00\u53d1\u4eba\u5458\u7684\u76f8\u5173\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9e\u73b0\u539f\u7406<\/h3>\n\n\n\n<p>\u5f53spring\u542f\u52a8\u7c7b\u8fd0\u884c\u65f6\u4f1a\u6267\u884crun\u65b9\u6cd5\uff0crun\u65b9\u6cd5\u4f1a\u52a0\u8f7dspring\u5bb9\u5668\uff0c\u5bb9\u5668\u4f1a\u6839\u636e\u4e3b\u914d\u7f6e\u7c7b\u7684\u6ce8\u89e3\u6267\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">@SpringBootApplication<\/h5>\n\n\n\n<p>\u4e3b\u8981\u5e94\u7528\u5728\u4e3b\u542f\u52a8\u7c7b\u4e0a\uff0c\u8868\u793a\u9700\u8981\u901a\u8fc7\u8fd9\u4e2a\u7c7b\u7684main\u65b9\u6cd5\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c@SpringBootApplication\u662f\u4e2a\u590d\u5408\u6ce8\u89e3\uff0c\u5305\u542b\u4e86\u53e6\u5916\u4e09\u4e2a\u6ce8\u89e3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>@SpringBootConfiguration<\/li>\n\n\n\n<li>@EnableAutoConfiguration<\/li>\n\n\n\n<li>@ComponentScan<\/li>\n<\/ul>\n\n\n\n<p>\u5148\u8bf4\u8bf4spring\u5982\u4f55\u89e3\u6790\u590d\u5408\u6ce8\u89e3\u3002spring\u89e3\u6790\u590d\u5408\u6ce8\u89e3\u7684\u6838\u5fc3\u673a\u5236\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>java\u53cd\u5c04\u3002\u5bf9\u6ce8\u89e3\u5904\u7406\u7684\u89e3\u6790java\u7684\u53cd\u5c04\u673a\u5236\u662f\u5fc5\u987b\u7684\uff0c\u53cd\u5c04\u4e3b\u8981\u7528\u4e8e\u83b7\u53d6\u7c7b\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u4e0a\u7684\u6ce8\u89e3\u4fe1\u606f\uff0c\u5178\u578b\u7684\u83b7\u53d6\u65b9\u6cd5\u5305\u62ecClass.getAnnotations()\u3001Method.getDeclaredAnnotations()\u7b49\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li>AnnotationUtils\u5de5\u5177\u7c7b\u3002\u8be5\u5de5\u5177\u7c7b\u5c01\u88c5\u4e86\u67e5\u627e\u3001\u5408\u5e76\u548c\u5904\u7406\u6ce8\u89e3\u7684\u76f8\u5173\u65b9\u6cd5\uff0c\u5c24\u5176\u5728\u5904\u7406\u7ee7\u627f\u6216\u7ec4\u5408\u6ce8\u89e3\u65f6\u53d1\u6325\u5173\u952e\u4f5c\u7528\u3002<\/li>\n\n\n\n<li>\u9012\u5f52\u89e3\u6790\u3002\u5f53\u9047\u5230\u4e00\u4e2a\u6ce8\u89e3\u65f6\uff0cSpring\u4f1a\u68c0\u67e5\u5b83\u662f\u5426\u662f\u590d\u5408\u6ce8\u89e3\uff0c\u5982\u679c\u662f\uff0c\u5219\u9012\u5f52\u6df1\u5165\u5176\u5143\u6ce8\u89e3\uff0c\u76f4\u5230\u63d0\u53d6\u51fa\u6240\u6709\u57fa\u7840\u6ce8\u89e3\u3002<\/li>\n\n\n\n<li>\u5408\u6210\u6ce8\u89e3\u3002Spring\u80fd\u5c06\u590d\u5408\u6ce8\u89e3\u4e2d\u7684\u591a\u4e2a\u5b50\u6ce8\u89e3\u5408\u6210\u4e00\u4e2a\u903b\u8f91\u6574\u4f53\uff0c\u89c6\u4e3a\u76f4\u63a5\u5e94\u7528\u4e8e\u76ee\u6807\u5143\u7d20\uff0c\u4ece\u800c\u81ea\u52a8\u5e94\u7528\u5176\u5bf9\u5e94\u7684\u884c\u4e3a\u3002<\/li>\n<\/ul>\n\n\n\n<p>@ComponentScan<\/p>\n\n\n\n<p>\u8ba9spring\u5bb9\u5668\u626b\u63cf\u5f53\u524d\u5305\u53ca\u5b50\u5305\u4e0b\u7684\u7c7b\uff0c\u5e76\u5c06\u628a\u5e26\u6709@Component\u3001@Service\u3001@Controller\u7b49\u6ce8\u89e3\u7684\u7c7b\u6ce8\u518c\u4e3abean<\/p>\n\n\n\n<p>@SpringBootConfiguration<\/p>\n\n\n\n<p>\u5355\u7eaf\u8ba9Spring\u5bb9\u5668\u628a\u4e3b\u542f\u52a8\u7c7b\u5f53\u4f5c\u4e00\u4e2a\u914d\u7f6e\u7c7b\u5904\u7406<\/p>\n\n\n\n<p>@EnableAutoConfiguration<\/p>\n\n\n\n<p>\u5f00\u542f\u81ea\u52a8\u88c5\u914d\u7684\u5173\u952e\u6ce8\u89e3\uff0c\u8be5\u6ce8\u89e3\u4e5f\u662f\u4e00\u4e2a\u590d\u5408\u6ce8\u89e3\uff0c\u5305\u542b\u4e86\u53e6\u5916\u4e24\u4e2a\u6ce8\u89e3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>@AutoConfigurationPackage<\/li>\n\n\n\n<li>@Import(AutoConfigurationImportSelector.class)<\/li>\n<\/ul>\n\n\n\n<p>@AutoConfigurationPackage\u3002\u4f1a\u8ba9spring\u5bb9\u5668\u626b\u63cf\u4e3b\u914d\u7f6e\u7c7b\u6240\u5728\u5305\u548c\u5b50\u5305\uff0c\u5c06\u6240\u6709\u7ec4\u4ef6\u626b\u63cf\u5e76\u52a0\u8f7d\u5230spring\u7684\u5bb9\u5668\u4e2d\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5728spring\u4e2d\u7f16\u5199\u7684\u4e1a\u52a1\u4ee3\u7801\u7684\u5305\u9700\u8981\u653e\u5728\u4e3b\u914d\u7f6e\u7c7b\u7edf\u8ba1\u76ee\u5f55\u4e0b\u3002<\/p>\n\n\n\n<p>@Import(AutoConfigurationImportSelector.class)<\/p>\n\n\n\n<p>\u4f7f\u7528@Import\u6ce8\u89e3\u5bfc\u5165\u7684\u7c7b\u4f1a\u88abSpring\u52a0\u8f7d\u5230IOC\u5bb9\u5668\u4e2d\uff0c@import\u5bfc\u5165bean\u5bb9\u5668\u7684\u65b9\u5f0f\u67094\u4e2d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bfc\u5165bean\uff08@Import(User.class)\uff09<\/li>\n\n\n\n<li>\u5bfc\u5165\u914d\u7f6e\u7c7b\uff08\u4f8b\u5982\u6709\u7528@Configuration\u4fee\u9970\u7684\u914d\u7f6e\u7c7bMyConfig\uff0c\u5e76\u4e14\u7c7b\u4e2d\u6709\u5e26\u6709@Bean\u6ce8\u89e3\u65b9\u6cd5\uff0c\u521b\u5efa\u5bf9\u8c61\u5b58\u5230IOC\u5bb9\u5668\uff0cbean\u540d\u79f0\u4e3a\uff1a\u9ed8\u8ba4\u65b9\u6cd5\u540d\u79f0\uff09<\/li>\n\n\n\n<li>\u5bfc\u5165ImportSelector\u7684\u5b9e\u73b0\u7c7b\u3002\u4e00\u822c\u7528\u4e8e\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u7c7b\u3002\u5f53\u5728Spring\u914d\u7f6e\u7c7b\u4e2d\u4f7f\u7528@Import\u6ce8\u89e3\u5e76\u6307\u5b9a\u5b9e\u73b0\u4e86ImportSelector\u63a5\u53e3\u7684\u7c7b\u65f6\uff0cSpring\u5bb9\u5668\u52a0\u8f7d\u65f6\u4f1a\u8c03\u7528\u8be5\u7c7b\u7684selectImports()\u65b9\u6cd5\uff0c\u6839\u636e\u65b9\u6cd5\u8fd4\u56de\u7684\u914d\u7f6e\u7c7b\u7684\u5168\u9650\u5b9a\u7c7b\u540d\u6765\u52a0\u8f7d\u76f8\u5e94\u7684\u914d\u7f6e\u7c7b\u3002<\/li>\n\n\n\n<li>\u5bfc\u5165ImportBeanDefinitionRegister\u7684\u5b9e\u73b0\u7c7b<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u91cc\u4f7f\u7528\u7684\u662f\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u6839\u636eselectImports()\u65b9\u6cd5\u7684\u5b9e\u73b0\u6765\u770b\u81ea\u52a8\u88c5\u914d\u7684\u5177\u4f53\u903b\u8f91\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1-1024x231.png\" alt=\"\" class=\"wp-image-1902\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1-1024x231.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1-300x68.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1-768x173.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1-1536x346.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-1.png 1768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u8981\u77e5\u9053\uff0c\u8fd9\u91cc\u8fd4\u56de\u7684\u662f\u9700\u8981\u81ea\u52a8\u88c5\u914d\u7684\u7c7b\u7684\u5168\u9650\u5b9a\u540d\u7684\u5b57\u7b26\u4e32\u5217\u8868\uff08\u770b\u4e0b\u56feautoConfigurationEntry.getConfigurations()\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"751\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6-1024x751.png\" alt=\"\" class=\"wp-image-1908\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6-1024x751.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6-300x220.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6-768x563.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6-110x80.png 110w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-6.png 1516w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u518d\u6765\u6211\u4eec\u53ef\u4ee5\u6d45\u770b\u4e0bspring\u5728ConfigurationClassParser\u4e2d\u5bf9Import\u6ce8\u89e3\u7684\u5904\u7406\u6d41\u7a0b\u3002\u9996\u5148\uff0c\u5982\u679c\u662fImportSelector\u7684\u5b9e\u73b0\u7c7b\u65f6\uff0c\u4f1a\u5c06\u88abimport\u4fee\u9970\u7684\u7c7b\u7684\u5143\u6ce8\u89e3\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165selectImports\u65b9\u6cd5\u4e2d\uff0c\u6240\u4ee5\u4e0a\u9762AnnotationMetadata\u4f20\u53c2\u662f\u975e\u7a7a\u7684\uff0c\u7136\u540e\u6211\u4eec\u518d\u770b\u4e0bisEnabled\u65b9\u6cd5\uff0c\u8fd9\u91cc\u5148\u5224\u65ad\u4e86\u662f\u5426\u662f\u5b50\u7c7b\uff0c\u5982\u679c\u662f\u5b50\u7c7b\u5c31\u8fd4\u56detrue\uff0c\u5982\u679c\u4e0d\u662f\u5b50\u7c7b\u5c31\u5224\u65ad\u73af\u5883\u53d8\u91cf\u662f\u5426\u7981\u7528\u4e86\u81ea\u52a8\u88c5\u914d\uff0c\u5982\u679c\u7981\u7528\u4e86\u81ea\u52a8\u88c5\u914d\uff0c\u5219\u8fd4\u56defalse\uff0c\u6240\u4ee5isEnabled\u4e00\u822c\u662f\u8fd4\u56de\u7684true<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"80\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-1024x80.png\" alt=\"\" class=\"wp-image-1913\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-1024x80.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-300x23.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-768x60.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-1536x120.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-10-2048x160.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"566\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-1024x566.png\" alt=\"\" class=\"wp-image-1911\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-1024x566.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-300x166.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-768x425.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-1536x850.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-8-2048x1133.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fdb\u5165getAutoConfigurationEntry\u51fd\u6570\u4e2d\uff0c\u4f1a\u5148\u4f5cisEnabled\u5224\u65ad\uff0c\u5982\u679c\u4e3afalse\u5219\u8fd4\u56de\u65b0\u7684AutoConfigurationEntry\u5bf9\u8c61\uff0c\u5217\u8868\u662f\u7a7a\u7684\uff0c\u6240\u4ee5\u6700\u540e\u662f\u8fd4\u56de\u7a7a\u6570\u7ec4\u3002\u5982\u679c\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5148\u83b7\u53d6\u5143\u6ce8\u89e3\u7684\u5c5e\u6027\uff0c\u6267\u884cgetCandidateConfigurations\u65b9\u6cd5\u83b7\u53d6\u914d\u7f6e\u4fe1\u606f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"34\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-7-1024x34.png\" alt=\"\" class=\"wp-image-1910\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-7-1024x34.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-7-300x10.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-7-768x26.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-7.png 1444w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"446\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2-1024x446.png\" alt=\"\" class=\"wp-image-1903\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2-1024x446.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2-300x131.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2-768x334.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2-1536x669.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-2.png 1640w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u518d\u5f80\u4e0b\u770bgetCandidateConfigurations\u7684\u65b9\u6cd5\u903b\u8f91\uff0c\u53d1\u73b0\u8be5\u65b9\u6cd5\u7684\u4e24\u4e2a\u5f62\u53c2\u5b9e\u9645\u6ca1\u6709\u4efb\u4f55\u5375\u7528\uff0c\u5355\u7eaf\u8fd4\u56de\u4e86SpringFactoriesLoader.loadFactoryNames\u65b9\u6cd5\u7684\u8fd4\u56de\u7ed3\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"110\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-1024x110.png\" alt=\"\" class=\"wp-image-1904\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-1024x110.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-300x32.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-768x82.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-1536x165.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-3-2048x219.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>this.getSpringFacoriesLoaderFactoryClass\u76f4\u63a5\u5c31\u8fd4\u56de\u4e86EnableAutoConfiguration.class\uff0c\u8fd9\u662f\u4e00\u4e2a\u6ce8\u89e3\u7c7b\uff0c\u6211\u4eec\u540e\u9762\u4f1a\u77e5\u9053\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u4f20\u8fd9\u4e2a\u53c2\u6570<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"335\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11-1024x335.png\" alt=\"\" class=\"wp-image-1914\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11-1024x335.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11-300x98.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11-768x251.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11-1536x503.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-11.png 1924w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>loadFactoryNames\u65b9\u6cd5\u8fd4\u56de\u7684\u662floadSpringFactories\u65b9\u6cd5\u8fd4\u56de\u96c6\u4e2d\u4ee5EnableAutoConfiguration.class\u7684\u5168\u9650\u5b9a\u540d\u4e3a\u952e\u7684\u5217\u8868<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"138\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4-1024x138.png\" alt=\"\" class=\"wp-image-1905\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4-1024x138.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4-300x40.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4-768x104.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4-1536x207.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-4.png 1676w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u6700\u540e\u6765\u770b\u770bloadSpringFactories\u65b9\u6cd5\u8fd4\u56de\u7684map\u5185\u5bb9\u662f\u5565<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    private static Map&lt;String, List&lt;String&gt;&gt; loadSpringFactories(@Nullable ClassLoader classLoader) {\n        MultiValueMap&lt;String, String&gt; result = (MultiValueMap)cache.get(classLoader);\n        if (result != null) {\n            return result;\n        } else {\n            try {\n                Enumeration&lt;URL&gt; urls = classLoader != null ? classLoader.getResources(\"META-INF\/spring.factories\") : ClassLoader.getSystemResources(\"META-INF\/spring.factories\");\n                MultiValueMap&lt;String, String&gt; result = new LinkedMultiValueMap();\n\n                while(urls.hasMoreElements()) {\n                    URL url = (URL)urls.nextElement();\n                    UrlResource resource = new UrlResource(url);\n                    Properties properties = PropertiesLoaderUtils.loadProperties(resource);\n                    Iterator var6 = properties.entrySet().iterator();\n\n                    while(var6.hasNext()) {\n                        Map.Entry&lt;?, ?&gt; entry = (Map.Entry)var6.next();\n                        String factoryTypeName = ((String)entry.getKey()).trim();\n                        String&#91;] var9 = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());\n                        int var10 = var9.length;\n\n                        for(int var11 = 0; var11 &lt; var10; ++var11) {\n                            String factoryImplementationName = var9&#91;var11];\n                            result.add(factoryTypeName, factoryImplementationName.trim());\n                        }\n                    }\n                }\n\n                cache.put(classLoader, result);\n                return result;\n            } catch (IOException var13) {\n                throw new IllegalArgumentException(\"Unable to load factories from location &#91;META-INF\/spring.factories]\", var13);\n            }\n        }\n    }<\/code><\/pre>\n\n\n\n<p>\u9996\u5148\u5224\u65ad\u7f13\u5b58\u4e2d\u5bf9\u5e94\u7c7b\u52a0\u8f7d\u5668\u7684\u5185\u5bb9\u662f\u5426\u4e3a\u7a7a\uff0c\u4e0d\u4e3a\u7a7a\u8fd4\u56de\uff0c\u4e3a\u7a7a\u5219\u8fdb\u884c\u8d44\u6e90\u52a0\u8f7d\uff0c\u56e0\u4e3a\u7c7b\u52a0\u8f7d\u5668\u4e0d\u4e3a\u7a7a\uff0c\u4e14\u662fAppClassLoader\uff0c\u6240\u4ee5\u4f1a\u52a0\u8f7dclasspath\u4e0b\u7684\u6240\u6709\u7b26\u5408\u8def\u5f84META-INF\/spring.factories\u7684\u6587\u4ef6\uff0c\u7136\u540e\u904d\u5386\u6bcf\u4e2a\u6587\u4ef6\u8d44\u6e90\u4e2d\u7684\u952e\u503c\u5bf9\uff0c\u56e0\u4e3a\u503c\u53ef\u80fd\u662f\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u9700\u8981\u8fdb\u884c\u5b57\u7b26\u4e32\u5904\u7406\u52a0\u8f7d\u6210String-List&lt;String>\u5e76\u5b58\u5230result\u4e2d\uff0c\u6700\u540e\u8fd4\u56de\u7ed3\u679c\u6570\u636e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"1024\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-14-859x1024.png\" alt=\"\" class=\"wp-image-2024\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-14-859x1024.png 859w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-14-252x300.png 252w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-14-768x916.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-14.png 1228w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u91cc\u4ee5\u4e00\u4e2aspring.factories\u7684\u6587\u4ef6\u4e3a\u4f8b\u89e3\u6790\u4e00\u4e0b\u6587\u4ef6\u683c\u5f0f\uff08\u5982\u4e0b\uff09\uff0c\u53ef\u4ee5\u770b\u51fa\u6765\u4e66\u5199\u683c\u5f0f\u662f\u4ee5\u952e\u503c\u5bf9\u7684\u65b9\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\norg.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\\\norg.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration,\\\norg.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\\\norg.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration,\\\norg.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration,\\\norg.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration,\\\norg.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration\n\norg.springframework.cloud.bootstrap.BootstrapConfiguration=\\\norg.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapConfiguration<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>spring.factories\u4e2d\u4e0d\u540c\u7684\u952e\u8868\u793a\u4e0d\u540c\u7684\u542b\u4e49\uff0c\u6bd4\u5982org.springframework.context.ApplicationListener\u8868\u793aspring\u4e0a\u4e0b\u6587\u7684\u4e8b\u4ef6\u76d1\u542c\u63a5\u53e3\uff0c\u503c\u8868\u793a\u7684\u662f\u5b9e\u73b0\u8fd9\u4e2a\u501f\u53e3\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\uff1borg.springframework.cloud.bootstrap.BootstrapConfiguration\u5219\u662f\u4e2a\u6ce8\u89e3\u7c7b\uff0c\u5bf9\u5e94\u7684\u503c\u8868\u793a\u9700\u8981\u5728\u81ea\u52a8\u88c5\u914d\u4e4b\u524d\u52a0\u8f7d\u7684\u914d\u7f6e\u7c7b<\/p>\n<\/blockquote>\n\n\n\n<p>\u81ea\u52a8\u88c5\u914d\u9700\u8981\u83b7\u53d6\u7684\u662f\u81ea\u52a8\u88c5\u914d\u6240\u9700\u7684\u7c7b\uff0c\u4e0d\u96be\u53d1\u73b0\u5728loadFactoryNames\u4e2d\u53d6\u7684\u662f\u4ee5factoryTypeName\u8fd9\u4e2a\u5f62\u53c2\u4e3akey\u7684\u76f8\u5e94\u503c\uff0c\u6211\u4eec\u5411\u4e0a\u770b\u770b\u6b64\u5f62\u53c2\u7684\u5b9e\u9645\u4f20\u503c\u662f\u4ec0\u4e48\u5462\uff1f\u53d1\u73b0\u6070\u597d\u5c31\u662fEnableAutoConfiguration\u6ce8\u89e3\u7c7b\u672c\u8eab\u3002\u8fd9\u91cc\u5c31\u5f88\u597d\u7684\u4f53\u73b0\u4e86spring boot\u7684\u7ea6\u5b9a\u4f18\u4e8e\u914d\u7f6e\u7684\u601d\u60f3\uff0cspring\u5176\u5b9e\u662f\u57fa\u4e8eSpring.factories\u7684\u914d\u7f6e\u89c4\u5219\u548c\u76f8\u5e94\u7684\u7c7b\u4e0a\u7684\u81ea\u52a8\u914d\u7f6e\u7684\u6ce8\u89e3\u6765\u7ed9\u51fa\u7684\u4e00\u5957\u9ed8\u8ba4\u7684\u7ea6\u5b9a\u89c4\u5219\uff0c\u907f\u514d\u4e86\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u7684\u5197\u4f59\u914d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"194\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36-1024x194.png\" alt=\"\" class=\"wp-image-1916\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36-1024x194.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36-300x57.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36-768x145.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36-1536x290.png 1536w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/\u622a\u5c4f2026-04-16-15.54.36.png 1978w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"190\" src=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-12-1024x190.png\" alt=\"\" class=\"wp-image-1917\" srcset=\"http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-12-1024x190.png 1024w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-12-300x56.png 300w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-12-768x142.png 768w, http:\/\/www.spiceandwolf.com.cn\/wp-content\/uploads\/2026\/04\/image-12.png 1166w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u81ea\u52a8\u88c5\u914d\u7684\u7cbe\u9ad3<\/h3>\n\n\n\n<p>\u53ef\u4ee5\u6307\u5b9a\u914d\u7f6e\u7684\u52a0\u8f7d\u6761\u4ef6\u548c\u52a0\u8f7d\u987a\u5e8f\uff0c\u4f8b\u5982:<\/p>\n\n\n\n<p>\u5982\u679c\u4e0d\u4f7f\u7528\u81ea\u52a8\u88c5\u914d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Configuration\npublic class StudentConfig {\n    @Bean\n    public Student student() {\n        \/\/ TODO\n        return new Student();\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@Configuration\npublic class SchoolConfig {\n    @ConditionalOnBean(Student.class)\n    @Bean\n    public School school() {\n        \/\/ TODO\n        return new School();\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u5219\u4e0a\u9762\u4e24\u4e2a\u914d\u7f6e\u7c7b\u662f\u6309\u5b57\u6bcd\u987a\u5e8f\u52a0\u8f7d\u7684\uff0c\u4f1a\u5148\u52a0\u8f7dSchoolConfig\u7c7b\uff0c\u800cSchoolConfig\u7c7b\u7684\u52a0\u8f7d\u6761\u4ef6\u662fStudentConfig\u7c7b\u5fc5\u987b\u5b58\u5728\uff0c\u8fd9\u65f6\u56e0\u4e3abeanDefinitionMap\u4e2d\u5e76\u6ca1\u6709\u52a0\u8f7dStudentConfig\uff0c\u6240\u4ee5StudentConfig\u914d\u7f6e\u7c7b\u5e76\u4e0d\u4f1a\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f7f\u7528\u81ea\u52a8\u88c5\u914d\uff08spring.factories\u4e2d\u7684org.springframework.boot.autoconfigure.EnableAutoConfiguration\u4e2d\u5305\u542b\u4ee5\u4e0b\u4e24\u4e2a\u7c7b\u7684\u5168\u9650\u5b9a\u540d\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class StudentConfig {\n    @Bean\n    public Student student() {\n        \/\/ TODO\n        return new Student();\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@AutoConfigureAfter(StudentConfig.class)\npublic class SchoolConfig {\n    @ConditionalOnBean(Student.class)\n    @Bean\n    public School school() {\n        \/\/ TODO\n        return new School();\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u52a0\u5165\u4e86@AutoConfigureAfter\u6ce8\u89e3\uff0cSchoolConfig\u4f1a\u5728StudentConfig\u7c7b\u4e4b\u540e\u52a0\u8f7d\uff0c\u8fd9\u6837\u5c31\u80fd\u6210\u529f\u52a0\u8f7d\u5230spring\u5bb9\u5668\u4e2d<\/p>\n\n\n\n<p>\u6240\u4ee5\u81ea\u52a8\u88c5\u914d\u7684\u7cbe\u9ad3\u662f\u53ef\u4ee5\u6307\u5b9a\u914d\u7f6e\u7684\u52a0\u8f7d\u6761\u4ef6\u548c\u52a0\u8f7d\u987a\u5e8f\u3002\u5178\u578b\u7684\u6ce8\u89e3\u6709<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ConditionalOnProperty<\/li>\n\n\n\n<li>ConditionalOnMissingBean<\/li>\n\n\n\n<li>ConditionalOnBean<\/li>\n\n\n\n<li>ConditionalOnMissingClass<\/li>\n\n\n\n<li>AutoConfigureAfter<\/li>\n\n\n\n<li>AutoConfigureBefore<\/li>\n\n\n\n<li>AutoConfigureOrder<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u9762\u5411\u9762\u8bd5\u603b\u7ed3<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\">\u8bb2\u8bb2Spring boot\u7684\u81ea\u52a8\u88c5\u914d\uff1f<\/h5>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5148\u8bb2\u81ea\u52a8\u88c5\u914d\u7684\u5b9a\u4e49\u3002Spring boot\u81ea\u52a8\u88c5\u914d\u6307\u7684\u662f\u57fa\u4e8e\u7ea6\u5b9a\u4f18\u4e8e\u914d\u7f6e\u7684\u601d\u60f3\uff0c\u81ea\u52a8\u5c06\u7b2c\u4e09\u65b9\u5e93\u6216\u5e38\u7528\u7ec4\u4ef6\u7684bean\u52a0\u8f7d\u5230spring\u5bb9\u5668\u4e2d\uff0c\u4ece\u800c\u5927\u5e45\u51cf\u5c11\u914d\u7f6e\u5de5\u4f5c\u7684\u673a\u5236\uff0c\u662fspring boot\u7684\u6838\u5fc3\u7279\u6027\u4e4b\u4e00<\/li>\n\n\n\n<li>\u518d\u8bf4\u81ea\u52a8\u88c5\u914d\u7684\u597d\u5904\n<ul class=\"wp-block-list\">\n<li>\u7b80\u5316\u914d\u7f6e\u3002\u4f20\u7edf\u7684\u624b\u52a8\u88c5\u914d\u65b9\u5f0f\u6709xml\u548c\u6ce8\u89e3\u65b9\u5f0f\uff0c\u9700\u8981\u624b\u52a8\u521b\u5efaxml\u6587\u4ef6\u6216\u8005java\u7c7b\u6765\u5b8c\u6210bean\u7684\u76f8\u5173\u914d\u7f6e\uff0c\u4f46\u662f\u81ea\u52a8\u88c5\u914d\u5c06\u5927\u91cf\u7684bean\u914d\u7f6e\u548c\u6ce8\u5165\u7684\u76f8\u5173\u903b\u8f91\u96c6\u6210\u5230\u542f\u52a8\u7c7b\u4e2d\uff0c\u53ea\u9700\u901a\u8fc7maven\u5f15\u5165\u76f8\u5173\u7684starter\u5305\u5c31\u80fd\u5b9e\u73b0\u81ea\u52a8\u914d\u7f6e\uff0c\u51cf\u5c11\u4e86\u5197\u4f59\u914d\u7f6e\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li>\u5f00\u7bb1\u5373\u7528\u3002\u53ea\u7528\u6781\u5c11\u7684\u914d\u7f6e\uff0c\u5c31\u80fd\u8ba9\u5e94\u7528\u5feb\u901f\u90e8\u7f72\u5e76\u6295\u5165\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>\u5b9e\u73b0\u4e86\u7248\u672c\u63a7\u5236\u548c\u4f9d\u8d56\u7ba1\u7406\u3002\u81ea\u52a8\u88c5\u914d\u7279\u6027\u5c06\u7248\u672c\u517c\u5bb9\u4ee3\u7801\u548c\u4f9d\u8d56\u63a7\u5236\u7684\u4ee3\u7801\u903b\u8f91\u4ea4\u7531\u542f\u52a8\u7c7b\u5b9e\u73b0\uff0c\u7b80\u5316\u4e86\u5f00\u53d1\u4eba\u5458\u7684\u76f8\u5173\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u6700\u540e\u8bf4\u81ea\u52a8\u88c5\u914d\u7684\u539f\u7406\u3002\u5f53spring\u542f\u52a8\u7c7b\u8fd0\u884c\u65f6\u4f1a\u6267\u884crun\u65b9\u6cd5\uff0crun\u65b9\u6cd5\u4f1a\u52a0\u8f7dspring\u5bb9\u5668\uff0c\u5bb9\u5668\u4f1a\u6839\u636e\u4e3b\u914d\u7f6e\u7c7b\u7684\u6ce8\u89e3\u6267\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\uff0c\u4fee\u9970\u4e3b\u542f\u52a8\u7c7b\u7684\u6ce8\u89e3\u4e3a@SpringBootAppliction\uff0c\u5b83\u662f\u4e00\u4e2a\u590d\u5408\u6ce8\u89e3\uff0c\u5305\u542b\u4e86@SpringBootConfiguration\u3001@ComponentScan\u548c@EnableAutoConfiguration\u8fd9\u4e09\u4e2a\u6ce8\u89e3\u7ec4\u6210\uff0c@SpringBootConfiguration\u6ce8\u89e3\u57fa\u672c\u7b49\u540c\u4e8e@Configuration\u6ce8\u89e3\uff0c\u8868\u793a\u4e3b\u542f\u52a8\u7c7b\u662f\u4e00\u4e2a\u914d\u7f6e\u7c7b\uff0cspring\u5bb9\u5668\u4f1a\u5c06\u5176\u6ce8\u518c\u4e3a\u4e00\u4e2abean\uff1b\u800c\u88ab@ComponentScan\u4fee\u9970\u7684\u7c7b\uff0cspring\u5bb9\u5668\u4f1a\u626b\u63cf\u5f53\u524d\u5305\u548c\u5b50\u5305\u4e0b\u7684\u6240\u6709\u7c7b\uff0c\u5c06\u88ab@Service\u3001@Component\u3001@Controller\u7b49\u6ce8\u89e3\u4fee\u9970\u7684\u7c7b\u6ce8\u518c\u4e3abean\uff1b\u800c@EnableAutoConfiguration\u5305\u542b\u4e24\u4e2a\u6ce8\u89e3@AutoConfigurationPackage\u548c@Import(AutoConfigurationImportSelector.class)\uff0c\u5176\u4e2d@AutoConfigurationPackage\u7528\u4e8e\u626b\u63cf\u5f53\u524d\u5305\u548c\u5b50\u5305\u4e0b\u7684\u6240\u6709\u7c7b\uff0c\u5c06\u6240\u6709\u7ec4\u4ef6\u626b\u63cf\u5e76\u52a0\u8f7d\u5230spring\u7684\u5bb9\u5668\u4e2d\uff0c\u4e0eComponentScan\u4e0d\u540c\u7684\u662f\u5176\u626b\u63cf\u7684\u662f\u7b2c\u4e09\u65b9\u5305\u6ce8\u89e3\u7684bean\uff1b@Import(AutoConfigurationImportSelector.class)\uff0c@import\u6ce8\u89e3\u4e00\u822c\u7528\u4e8e\u5c06\u7c7b\u4f5c\u4e3abean\u5bfc\u5165spring\u5bb9\u5668\u4e2d\uff0c\u65b9\u5f0f\u6709\u56db\u79cd\uff0c\u5206\u522b\u662f\u5bfc\u5165bean\u3001\u5bfc\u5165\u914d\u7f6e\u7c7b\u3001\u5bfc\u5165ImportSelector\u7684\u5b9e\u73b0\u7c7b\u3001\u5bfc\u5165ImportBeanDefinitionRegister\u7684\u5b9e\u73b0\u7c7b\uff0c\u8fd9\u91cc\u7528\u7684\u662f\u7b2c\u4e09\u79cd\u65b9\u5f0f\uff0c\u4f1a\u5c06\u5b9e\u73b0\u7c7b\u4e2d\u7684selectImports\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u5217\u8868\u4f5c\u4e3a\u5168\u9650\u5b9a\u7c7b\u540d\u6765\u52a0\u8f7d\u76f8\u5e94\u7684\u914d\u7f6e\u7c7b\uff0c\u8fd9\u91cc\u5b9e\u73b0\u7684\u903b\u8f91\u6d41\u7a0b\u662f\uff1a\n<ol class=\"wp-block-list\">\n<li>\u5148\u5224\u65ad\u662f\u5426\u542f\u7528\u4e86\u81ea\u52a8\u88c5\u914d\u3002\u5224\u65ad\u5f53\u524d\u7c7b\u662f\u5426\u662fAutoConfigurationImportSelector.class\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u8bf4\u660e\u662f\u8fd9\u4e2a\u7c7b\u7684\u5b50\u7c7b\uff0c\u5219\u76f4\u63a5true\uff1b\u5982\u679c\u662f\uff0c\u518d\u8fd4\u56de\u5f53\u524d\u73af\u5883\u53d8\u91cf\u4e2d\u7684spring.boot.enableautoconfiguration\u7684\u503c\uff0c\u5982\u679c\u662ffalse\uff0c\u5219\u4e0d\u8fdb\u884c\u81ea\u52a8\u88c5\u914d\uff0c\u8fd4\u56de\u7a7a\u5217\u8868<\/li>\n\n\n\n<li>\u518d\u901a\u8fc7loadSpringFactories(@Nullable ClassLoader classLoader)\u65b9\u6cd5\u83b7\u53d6spring.factories\u7684\u914d\u7f6e\u4fe1\u606f\u3002\n<ol class=\"wp-block-list\">\n<li>\u5148\u4ece\u4ee5classloader-MultiValueMap&lt;String, String>\u4f5c\u4e3a\u952e\u503c\u5bf9\u7684map\u4e2d\u83b7\u53d6\u4f20\u5165\u7684\u7c7b\u52a0\u8f7d\u5668\u5bf9\u5e94\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u5982\u679c\u5b58\u5728\uff0c\u5219\u8fd4\u56de\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219<\/li>\n\n\n\n<li>\u5224\u65ad\u4f20\u5165\u7684\u7c7b\u52a0\u8f7d\u5668\u662f\u5426\u4e3a\u7a7a\uff0c\u5982\u679c\u4e0d\u4e3a\u7a7a\uff0c\u5219\u83b7\u53d6classLoader.getResources(&#8220;META-INF\/spring.factories&#8221;)\u4f5c\u4e3a\u7ed3\u679c\u6570\u636e\uff0c\u5982\u679c\u4e3a\u7a7a\u5219\u83b7\u53d6ClassLoader.getSystemResources(&#8220;META-INF\/spring.factories&#8221;)\u4f5c\u4e3a\u7ed3\u679c\u6570\u636e<\/li>\n\n\n\n<li>\u5904\u7406\u7ed3\u679c\u6570\u636e\u3002\u4e0a\u4e00\u90e8\u62ff\u5230\u7684\u4ec5\u4ec5\u662f\u539f\u6570\u636e\uff0c\u56e0\u4e3aspring.factories\u5b58\u50a8\u7684\u952e\u548c\u503c\u90fd\u662f\u5b57\u7b26\u4e32\u6570\u636e\uff0c\u6d89\u53ca\u5230\u590d\u6570\u4e2a\u503c\u4f1a\u4ee5\u9017\u53f7\u5206\u9694\uff0c\u6240\u4ee5\u8fd9\u91cc\u4f1a\u5c06\u503c\u7684\u6570\u636e\u5904\u7406\u6210list\u5e76\u548ckey\u5c01\u88c5Map&lt;String, List&lt;String>>\u7ed3\u6784\u5b58\u50a8\u5728\u6570\u636e\u7ed3\u6784\u4e2d(MultiValueMap\u672c\u8eab\u5c31\u7ee7\u627f\u81eaMap&lt;K, List&lt;V>>)<\/li>\n\n\n\n<li>\u53d6EnableAutoConfiguration.class\u7684\u5168\u9650\u5b9a\u540d\u4e3akey\u7684\u503c\uff0c\u5373\u6240\u6709\u7684\u81ea\u52a8\u88c5\u914d\u914d\u7f6e\u7c7b\u7684\u5168\u9650\u5b9a\u540d\u7684list\u8fd4\u56de<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>\u6700\u540e\u57fa\u4e8e\u8fd4\u56de\u7684\u5168\u9650\u5b9a\u540d\u52a0\u8f7d\u914d\u7f6e\u7c7b<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>\u81ea\u52a8\u88c5\u914d\u539f\u7406\u603b\u7ed3\uff1aspring boot\u5176\u5b9e\u662f\u901a\u8fc7spring.factories\u6587\u4ef6\u7684\u914d\u7f6e\u89c4\u7ea6\u548cspring\u5bf9\u6587\u4ef6\u4e2d\u81ea\u52a8\u914d\u7f6e\u7c7b\u7684\u52a0\u8f7d\u903b\u8f91\u5b9e\u73b0\u4e86\u81ea\u52a8\u88c5\u914d\uff0c\u5145\u5206\u4f53\u73b0\u4e86\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\u7684\u8bbe\u8ba1\u601d\u60f3<\/li>\n\n\n\n<li>\u81ea\u52a8\u88c5\u914d\u7684\u7cbe\u9ad3\u3002\u53ef\u4ee5\u6307\u5b9a\u914d\u7f6e\u7684\u52a0\u8f7d\u6761\u4ef6\u548c\u52a0\u8f7d\u987a\u5e8f\uff0c\u4f8b\u5982&#8230;<\/li>\n<\/ol>\n\n\n\n<h5 class=\"wp-block-heading\">spring boot\u81ea\u52a8\u88c5\u914d\u7684\u539f\u7406\u662f\u4ec0\u4e48\uff08\u540c\u4e0a3\uff09\uff1f<\/h5>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u4e49 Spring boot\u81ea\u52a8\u88c5\u914d\u6307\u7684\u662f\u901a\u8fc7\u7ea6\u5b9a\u4f18\u4e8e\u914d\u7f6e\u7684\u601d\u60f3\uff0c\u81ea\u52a8\u5c06\u7b2c\u4e09\u65b9\u5e93\u6216\u5e38\u7528\u7ec4\u4ef6\u7684bean\u52a0\u8f7d\u5230sp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,84,93],"tags":[],"class_list":["post-1894","post","type-post","status-publish","format-standard","hentry","category-code","category-spring","category-spring-boot-code"],"_links":{"self":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1894"}],"version-history":[{"count":42,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1894\/revisions"}],"predecessor-version":[{"id":2029,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1894\/revisions\/2029"}],"wp:attachment":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1894"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}