{"id":10879,"date":"2023-04-21T20:58:09","date_gmt":"2023-04-21T12:58:09","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10879"},"modified":"2023-04-21T20:58:09","modified_gmt":"2023-04-21T12:58:09","slug":"%e5%88%a8%e6%9e%90-springboot-%e8%87%aa%e5%8a%a8%e8%a3%85%e9%85%8d%e5%8e%9f%e7%90%86%ef%bc%8c%e5%85%b6%e5%ae%9e%e5%be%88%e7%ae%80%e5%8d%95","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10879","title":{"rendered":"\u5228\u6790 SpringBoot \u81ea\u52a8\u88c5\u914d\u539f\u7406\uff0c\u5176\u5b9e\u5f88\u7b80\u5355"},"content":{"rendered":"\n<p><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e00\u65e5\u6211\u5728\u6109\u5feb\u5f97\u9068\u6e38\u65f6\uff0c\u770b\u5230\u6709\u9c7c\u53cb\u5728\u95ee\uff1aSpringBoot \u4e2d\u5f15\u5165\u4e86 Nacos \u4f9d\u8d56\u4e3a\u5565\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 Nacos \u4e2d\u7684\u76f8\u5173\u529f\u80fd\u5440\uff01<\/p>\n\n\n\n<p>\u8ba4\u771f\u601d\u8003\u4e86\u4e00\u756a\uff0c\u6211\u7acb\u9a6c\u5c31\u60f3\u8bf4\uff0c<strong>\u81ea\u52a8\u88c5\u914d<\/strong>\uff0c\u4f46\u8fd9\u79cd\u56de\u7b54\u600e\u4e48\u80fd\u4f53\u73b0\u6211\u7684<code>\u725b\u903c<\/code>\u5462\uff01\uff08\u725b\u903c\u75c7\u72af\u4e86\uff09<\/p>\n\n\n\n<p>\u601d\u7d22\u4e07\u5343\uff0c\u6211\u7ed9\u51fa\u4e86\u4e0b\u9762\u7684\u56de\u7b54\uff1a\u56e0\u4e3a SpringBoot \u7684\u5b97\u65e8\u662f\uff0c<strong>\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e<\/strong>\uff0c\u4e00\u5207\u90fd\u7531\u7ea6\u5b9a\u6240\u51b3\u5b9a\u3002\u5f53\u4f60\u5f15\u5165 Nacos \u7684\u4f9d\u8d56\u65f6\uff0c\u5c31\u548c SpringBoot \u8fbe\u6210\u4e86\u4e00\u4e2a\u7ea6\u5b9a<code>\u73af\u5883\u4e2d\u9700\u8981\u6709 Nacos \u76f8\u5173\u529f\u80fd<\/code>\uff0c\u6240\u4ee5 SpringBoot \u5c31\u5728\u542f\u52a8\u7684\u65f6\u5019\u5c06 Nacos \u4e2d\u6240\u9700\u8981\u7684\u529f\u80fd\u81ea\u52a8\u88c5\u914d\u597d\u4e86\u3002<\/p>\n\n\n\n<p>\u6d0b\u6d0b\u6d12\u6d12\u4e00\u6bb5\u8bdd\u629b\u51fa\uff0c\u7136\u800c\u5e76\u6ca1\u6709\u8fbe\u5230\u90a3\u79cd\u6e85\u8d77\u5343\u5c42\u6d6a\u82b1\u7684\u6548\u679c\uff0c\u53cd\u5012\u662f\u4e0b\u9762\u7684\u4e00\u53e5\u53e5\u201d\u8fd9\u5c31\u662f SpringBoot \u7684\u81ea\u52a8\u88c5\u914d\u201c \u6765\u7684\u6548\u679c\u597d\u3002<\/p>\n\n\n\n<p>what\uff1f<\/p>\n\n\n\n<p>\u65e9\u77e5\u9053\u4ed6\u4eec\u90fd\u662f\u90a3\u4e48\u7b80\u5355\u7684\u4eba\uff0c\u6211\u53c8\u4f55\u5fc5\u88c5\u6df1\u6c89\uff0c\u5c0f\u4e11\u7adf\u7136\u662f\u6211\u81ea\u5df1\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-287.png\" alt=\"\" class=\"wp-image-10880\" width=\"128\" height=\"99\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-287.png 364w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-287-300x232.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-287-230x178.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-287-350x271.png 350w\" sizes=\"(max-width: 128px) 100vw, 128px\" \/><\/figure><\/div>\n\n\n\n<p>\u65e2\u7136\u63d0\u5230\u4e86\u81ea\u52a8\u88c5\u914d\uff0c\u800c\u65e5\u5e38\u5de5\u4f5c\u4e2d\u57fa\u672c\u79bb\u4e0d\u5f00 SpringBoot \u5e76\u4e14\u81ea\u52a8\u88c5\u914d\u53c8\u662f SpringBoot \u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u529f\u80fd\uff0c\u90a3\u6211\u6709\u4ec0\u4e48\u7406\u7531\u4e0d\u53bb\u6df1\u5165\u7814\u7a76\u4e00\u756a\u5462\uff01<\/p>\n\n\n\n<p>\u6211\u5e38\u6559\u5bfc\u4f60\u4eec\u8981\u6252\u5149\u5185\u88e4\u770b\u4e2a\u7a76\u7adf\uff0c\u4eca\u5929\u54b1\u5c31\u6765\u6252\u4e00\u6252\u81ea\u52a8\u88c5\u914d\u7684\u529f\u80fd\u59cb\u672b\u3002<\/p>\n\n\n\n<p>\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ol><li>JDK\u4e3a 1.8<\/li><li>SpringBoot \u4e3a 2.5.5<\/li><\/ol>\n\n\n\n<p><strong>1\u3001\u624b\u5199\u4e00\u4e2a Starter<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728\u5206\u6790\u4e4b\u524d\uff0c\u6211\u8ba4\u4e3a\u6709\u5fc5\u8981\u5148\u624b\u52a8\u5b9e\u73b0\u4e00\u4e2a Starter \u3002\u56e0\u4e3a\u81ea\u52a8\u88c5\u914d\u8fd9\u4e2a\u529f\u80fd\u6211\u4eec\u8981\u7406\u89e3\u5b83\u5230\u5e95\u662f\u5728\u81ea\u52a8\u88c5\u914d\u4e2a\u4ec0\u4e48\u4e1c\u897f\uff0c\u5bf9\u5427\uff01<\/p>\n\n\n\n<p>\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u81ea\u52a8\u88c5\u914d\u6211\u4eec\u5f15\u5165\u7684\u4e00\u4e2a\u4e2a Starter \u3002\u90a3\u662f\u4ec0\u4e48 Starter \u90fd\u80fd\u591f\u88ab\u88c5\u914d\u561b\uff0c\u6211\u5199\u4e2a Hello World \u5b83\u4e5f\u80fd\u7ed9\u6211\u81ea\u52a8\u88c5\u914d\uff1f<\/p>\n\n\n\n<p>\u5f53\u7136\u662f\u4ec0\u4e48\u90fd\u80fd\u591f\u81ea\u52a8\u88c5\u914d\u4e86\uff0c\u4f46\u524d\u63d0\u662f\u6211\u4eec\u7f16\u5199\u7684 Starter \u5fc5\u987b\u8981\u7b26\u5408 SpringBoot \u7684\u81ea\u52a8\u88c5\u914d\u89c4\u5219\uff0c\u5426\u5219\u662f\u4e0d\u884c\u7684\uff0c\u90a3\u5230\u5e95\u662f\u4ec0\u4e48\u89c4\u5219\u5462\uff01<\/p>\n\n\n\n<p>1\u3001\u5728 resources\/META-INF \u76ee\u5f55\u4e0b\u5fc5\u987b\u8981\u6709 spring.factories<\/p>\n\n\n\n<p>2\u3001spring.factories \u6587\u4ef6\u4e2d\u5fc5\u987b\u8981\u6709 org.springframework.boot.autoconfigure.EnableAutoConfiguration \u5bf9\u5e94\u7684\u914d\u7f6e\u7c7b<\/p>\n\n\n\n<p>3\u3001\u8981\u88ab\u4f7f\u7528\u7684 Bean \u5fc5\u987b\u6b63\u5e38\u88ab\u626b\u63cf\u5230<\/p>\n\n\n\n<p>ok\uff0c\u4e86\u89e3\u8fd9\u4e48\u591a\u90a3\u5c31\u5f00\u59cb\u624b\u5199\u4e00\u4e2a Starter \u3002<\/p>\n\n\n\n<p><strong>1.1 \u5148\u521b\u5efa\u4e00\u4e2a SpringBoot \u9879\u76ee<\/strong><\/p>\n\n\n\n<p>\u9879\u76ee\u53ef\u4ee5\u4e0d\u9700\u8981\u542f\u52a8\u7c7b\uff0c\u56e0\u4e3a\u672c\u6765\u4e5f\u6ca1\u6253\u7b97\u8ba9\u4ed6\u8fd0\u884c\uff0c\u9879\u76ee\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-288.png\" alt=\"\" class=\"wp-image-10881\" width=\"425\" height=\"278\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288.png 780w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288-300x196.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288-768x502.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288-230x150.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288-350x229.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-288-480x314.png 480w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/figure><\/div>\n\n\n\n<ul><li>MyStarterApplication\uff1a\u4e3b\u914d\u7f6e\u7c7b\u3002<\/li><li>spring.factories\uff08\u91cd\u70b9\uff09\uff1a\u914d\u7f6e\u6587\u4ef6\uff0c\u544a\u77e5 SpringBoot \u8981\u88c5\u914d\u7684\u914d\u7f6e\u7c7b\u5728\u54ea\u3002<\/li><li>MyStarterService\uff1a\u4e1a\u52a1\u7c7b\u3002<\/li><\/ul>\n\n\n\n<p>1\u3001MyStarterApplication<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u626b\u63cf\u89c4\u5219\uff0c\u5c06\u8981\u88ab\u7ba1\u7406\u7684 Bean \u4ea4\u7ed9 IOC \u5bb9\u5668\n@ComponentScan(\"cn.j3.mystarter\")\npublic class MyStarterApplication {\n    \/\/ \u914d\u7f6e\n}\n<\/pre>\n\n\n\n<p>2\u3001spring.factories<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\ncn.j3.mystarter.MyStarterApplication<\/pre>\n\n\n\n<p>3\u3001MyStarterService<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Service\npublic class MyStarterService {\n\n    public void myService(String example) {\n        System.out.println(\"\u60a8\u4f20\u5165\u5f97\u503c\u4e3a\uff1a\" + example);\n    }\n}\n\n<\/pre>\n\n\n\n<p>ok\uff0c\u5c31\u8fd9\u70b9\u4e1c\u897f\u4e00\u4e2a Starter \u5c31\u7b97\u662f\u5199\u597d\u4e86\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u5728<code>\u53e6\u5916\u4e00\u4e2a\u9879\u76ee<\/code>\u4e2d\u5f15\u5165\u8fd9\u4e2a\u9879\u76ee\u4f9d\u8d56\uff0c\u5e76\u542f\u52a8\u53e6\u5916\u4e00\u4e2a\u9879\u76ee\uff0c\u6700\u7ec8\u53ef\u4ee5\u53d1\u73b0 MyStarterService \u4e1a\u52a1\u7c7b\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u53e6\u4e00\u4e2a\u9879\u76ee pom \u6587\u4ef6\u5f15\u5165\u4e0b\u9762\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;dependency>\n    &lt;groupId>cn.j3&lt;\/groupId>\n    &lt;artifactId>my-starter&lt;\/artifactId>\n    &lt;version>0.0.1-SNAPSHOT&lt;\/version>\n&lt;\/dependency>\n<\/pre>\n\n\n\n<p>\u6d4b\u8bd5 controller<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@RestController\n@RequestMapping(\"\/test\")\npublic class MvcTestController {\n\n    \/\/ \u6b63\u5e38\u6ce8\u5165\n    @Autowired\n    private MyStarterService myStarterService;\n\n    @GetMapping(\"\/mvc\")\n    public String mvcTest(){\n        System.out.println(\"mvc success!\");\n        \/\/ \u6b63\u5e38\u8c03\u7528\n        myStarterService.myService(\"\u6d4b\u8bd5\u81ea\u52a8\u88c5\u914d\uff01\");\n        return \"success!\";\n    }\n}\n<\/pre>\n\n\n\n<p>\u63a7\u5236\u53f0\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mvc success!\n\u60a8\u4f20\u5165\u5f97\u503c\u4e3a\uff1a\u6d4b\u8bd5\u81ea\u52a8\u88c5\u914d\uff01<\/pre>\n\n\n\n<p>\u81ea\u5b9a\u4e49 starter \u7f16\u5199\u5b8c\u6210\uff0c\u662f\u4e0d\u662f\u89c9\u5f97\u975e\u5e38\u7b80\u5355\u3002<\/p>\n\n\n\n<p><strong>2\u3001\u63a2\u7a76\u81ea\u52a8\u88c5\u914d\u539f\u7406<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e0a\u9762\u6211\u4eec\u81ea\u5b9a\u4e49\u7684 starter \u751f\u6548\u7684\u8fc7\u7a0b\u5c31\u662f SpringBoot \u81ea\u52a8\u88c5\u914d\u7684\u8fc7\u7a0b\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u662f\u5728\u4e00\u4e2a\u9879\u76ee\u4e2d\u5f15\u5165\u4e86\u6211\u4eec\u81ea\u5b9a\u4e49\u7684 starter \u800c\u91cc\u9762\u7684\u529f\u80fd\u5c31\u53ef\u4ee5\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u90a3\u6211\u4eec\u5148\u6765\u5206\u6790\u4e00\u4e0b\u81ea\u5b9a\u4e49\u7684 starter \u3002<\/p>\n\n\n\n<p>\u5728 SpringBoot \u4e2d\u8981\u60f3\u8ba9\u4e00\u4e2a\u529f\u80fd\u88ab IOC \u5bb9\u5668\u7ba1\u7406\u6211\u4eec\u5e94\u8be5\u600e\u4e48\u505a\uff0c\u5bf9\uff0c\u5c31\u662f\u8ba9\u7c7b\u88ab SpringBoot \u626b\u63cf\u5230\u5e76\u653e\u5165\u5bb9\u5668\u4e2d\u3002<\/p>\n\n\n\n<p>\u5728\u6211\u4eec\u81ea\u5b9a\u4e49\u7684 starter \u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9\u6837\u7684\u4e00\u4e2a\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\ncn.j3.mystarter.MyStarterApplication\n<\/pre>\n\n\n\n<p>\u8fd9\u662f<code>\u6838\u5fc3<\/code>\uff0c\u5b83\u662f\u529f\u80fd\u751f\u6548\u7684\u6e90\u5934\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u6211\u4eec\u6709\u4e86\u4e0a\u9762\u7684\u914d\u7f6e\uff0c\u4f7f\u5f97 MyStarterApplication \u7c7b\u6210\u4e3a\u4e86 SpringBoot \u7684\u4e00\u4e2a\u914d\u7f6e\u7c7b\u5f53\u914d\u7f6e\u7c7b\u88ab\u52a0\u8f7d\u5230\u5bb9\u5668\u4e2d\u65f6\uff0c\u914d\u7f6e\u7c7b\u4e0a\u7684\u6ce8\u89e3\u4ece\u800c\u5c31\u751f\u6548\uff0c\u8fdb\u800c\u5e26\u52a8\u4e86\u6574\u4e2a starter \u4e2d\u7684 Bean \u90fd\u88ab\u5bb9\u5668\u6240\u7ba1\u7406\u3002<\/p>\n\n\n\n<p>\u90a3\u6e90\u5934\u6211\u4eec\u662f\u627e\u5230\u4e86\uff0c\u5c31\u662f <code>spring.factories<\/code> \u6587\u4ef6\uff0c\u53ea\u8981\u914d\u7f6e\u7684\u8fd9\u4e2a\u6587\u4ef6\u751f\u6548\uff0cstarter \u5c31\u4f1a\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5 <code>spring.factories<\/code> \u6587\u4ef6\u662f\u5982\u4f55\u751f\u6548\u7684\u5462\uff01<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u8bf4\u7ed3\u679c\u628a\uff01\u5c31\u662f <code>@SpringBootApplication<\/code> \u8fd9\u4e2a\u6ce8\u89e3\u3002\u53ef\u4ee5\u8bf4\uff0c\u5728\u6574\u4e2a SpringBoot \u4e2d\u8fd9\u4e2a\u6ce8\u89e3\u662f\u975e\u5e38\u91cd\u8981\uff0c\u5982\u679c\u6ca1\u6709\u5b83\uff0c\u90a3\u4e48\u50cf\u81ea\u52a8\u88c5\u914d\u3001\u5305\u626b\u63cf\u7b49\u529f\u80fd\u90fd\u4f1a\u5931\u6548\uff0c\u6240\u4ee5\u672c\u6b21\u6211\u4eec\u5206\u6790\u6e90\u7801\u7684\u5165\u53e3\u5c31\u662f\u8fd9\u4e2a\u6ce8\u89e3\u4e86\u3002<\/p>\n\n\n\n<p>\u5728\u6211\u4eec\u6b65\u6b65\u4e3a\u8425\uff0c\u5c42\u5c42\u9012\u8fdb\u7684\u60c5\u51b5\u4e0b\uff0c\u7ec8\u4e8e\u662f\u5206\u6790\u5230\u4e86 <code>@SpringBootApplication<\/code> \u6ce8\u89e3\uff0c\u53ef\u559c\u53ef\u8d3a\uff01<\/p>\n\n\n\n<p><strong>2.1 @SpringBootApplication<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u6ce8\u89e3\u4e0d\u7528\u6211\u591a\u8bf4\uff0c\u5927\u4f19\u4e5f\u90fd\u77e5\u9053\u5b83\u5728\u54ea\u5427\uff01\u2014\u2014 <code>\u4e3b\u7c7b<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u6211\u4eec\u8981\u5206\u6790\u7684\u6ce8\u89e3\n@SpringBootApplication\npublic class StudySpringbootApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(StudySpringbootApplication.class, args);\n    }\n}<\/pre>\n\n\n\n<p>\u5728 IDEA \u4e2d\u70b9\u8fdb\u8fd9\u4e2a\u6ce8\u89e3\u770b\u770b\u5b83\u7684\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Target(ElementType.TYPE)\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Inherited\n@SpringBootConfiguration\n@EnableAutoConfiguration\n@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),\n      @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })\npublic @interface SpringBootApplication {\n\n   @AliasFor(annotation = EnableAutoConfiguration.class)\n   Class&lt;?>[] exclude() default {};\n\n   @AliasFor(annotation = EnableAutoConfiguration.class)\n   String[] excludeName() default {};\n\n   @AliasFor(annotation = ComponentScan.class, attribute = \"basePackages\")\n   String[] scanBasePackages() default {};\n\n   @AliasFor(annotation = ComponentScan.class, attribute = \"basePackageClasses\")\n   Class&lt;?>[] scanBasePackageClasses() default {};\n\n   @AliasFor(annotation = ComponentScan.class, attribute = \"nameGenerator\")\n   Class&lt;? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;\n\n   @AliasFor(annotation = Configuration.class)\n   boolean proxyBeanMethods() default true;<\/pre>\n\n\n\n<p>\u7b80\u5355\u7684\u8bf4\u4e00\u4e0b\u8fd9\u4e2a\u6ce8\u89e3\u6240\u5305\u542b\u7684\u6e90\u7801\u529f\u80fd<\/p>\n\n\n\n<ol><li>@SpringBootConfiguration\uff1a\u6807\u6ce8\u7684\u7c7b\u4e3a SpringBoot \u7684\u4e00\u4e2a\u914d\u7f6e\u7c7b<\/li><li><strong>@EnableAutoConfiguration<\/strong>\uff1a\u81ea\u52a8\u914d\u7f6e\u6ce8\u89e3\uff08\u91cd\u70b9\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff09<\/li><li>@ComponentScan\uff1a\u5305\u626b\u63cf\u6ce8\u89e3<\/li><li>\u6ce8\u89e3\u5c5e\u6027\u4e3b\u8981\u662f\u5b9a\u4e49\u4e86\u6392\u9664\u4e00\u4e9b\u4e0d\u7528\u88c5\u914d\u7684\u7c7b\uff0c\u6839\u636e Class \u3001name \u7b49\u89c4\u5219\u8fdb\u884c\u6392\u9664<\/li><li>\u6fc0\u6d3b @Component \u626b\u63cf\u7684 @ComponentScan<\/li><\/ol>\n\n\n\n<p>\u5f88\u660e\u663e\u6211\u4eec\u63a5\u4e0b\u6765\u8981\u5206\u6790\u7684\u91cd\u70b9\u662f <code>@EnableAutoConfiguration<\/code> \u6ce8\u89e3<\/p>\n\n\n\n<p><strong>2.2 @EnableAutoConfiguration<\/strong><\/p>\n\n\n\n<p>\u770b\u540d\u5b57\u6211\u4eec\u5c31\u80fd\u731c\u51fa\u8fd9\u4e2a\u6ce8\u89e3\u7684\u4f5c\u7528\uff1a\u5f00\u542f\u81ea\u52a8\u914d\u7f6e\u3002\u5b83\u4f4d\u4e8e spring-boot-autoconfigure \u5305\u5185\uff0c\u5f53\u6211\u4eec\u4f7f\u7528 @SpringBootApplication \u6ce8\u89e3\u65f6\uff0c\u5b83\u5c31\u4f1a\u81ea\u52a8\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6765\u770b\u770b\u5b83\u7684\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Target(ElementType.TYPE)\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Inherited\n@AutoConfigurationPackage\n@Import(AutoConfigurationImportSelector.class)\npublic @interface EnableAutoConfiguration {\n    \/\/ \u7528\u6765\u8986\u76d6\u914d\u7f6e\u5f00\u542f \/ \u5173\u95ed\u81ea\u52a8\u914d\u7f6e\u7684\u529f\u80fd\n    String ENABLED_OVERRIDE_PROPERTY = \"spring.boot.enableautoconfiguration\";\n    \/\/ \u6839\u636e\u7c7b\u6392\u9664\u6307\u5b9a\u7684\u81ea\u52a8\u914d\u7f6e\n    Class&lt;?>[] exclude() default {};\n    \/\/ \u6839\u636e\u7c7b\u540d\u6392\u9664\u6307\u5b9a\u7684\u81ea\u52a8\u914d\u7f6e\n    String[] excludeName() default {};\n}\n<\/pre>\n\n\n\n<p>\u5bf9\u4e8e @EnableAutoConfiguration \u6ce8\u89e3\u7684\u5c5e\u6027\u5927\u4f19\u770b\u6211\u6807\u6ce8\u7684\u6ce8\u91ca\u5c31\u884c\uff0c\u4f46\u6211\u4eec\u8fd8\u770b\u5230\u8fd9\u4e2a\u6ce8\u89e3\u5f0f\u53c8\u6807\u6ce8\u4e86\u5176\u5b83\u4e24\u4e2a\u6ce8\u89e3\u5206\u522b\u4e3a\uff1a<\/p>\n\n\n\n<ol><li>@AutoConfigurationPackage<\/li><li>@Import(AutoConfigurationImportSelector.class)<\/li><\/ol>\n\n\n\n<p>@AutoConfigurationPackage \u6ce8\u89e3\u7684\u529f\u80fd\u6211\u5c31\u7b80\u5355\u8bf4\u4e00\u4e0b\uff0c\u5c06\u6ce8\u89e3\u6240\u5728\u7684\u5305\u8def\u5f84\u52a0\u5165\u5230\u4e00\u4e2a\u4e13\u95e8\u8bb0\u5f55packageNames\u7684\u96c6\u5408\u91cc\uff0c\u90a3\u81f3\u4e8e\u4e3a\u5565\u52a0\u5230\u8fd9\u4e2a\u96c6\u5408\u91cc\uff0c\u6211\u60f3\u5c31\u662f\u4e3a\u4e86\u5305\u626b\u63cf\u5427\uff01<\/p>\n\n\n\n<p>\u4e0b\u9762\u5c31\u662f @Import \u6ce8\u89e3\u4e86\uff0c\u5728\u5b66\u4e60 Spring \u7684\u65f6\u5019\u6211\u4eec\u4e5f\u7ecf\u5e38\u4f7f\u7528 \u6807\u7b7e\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u8fd8\u6709\u6ca1\u6709\u5370\u8c61\u4e86\u3002\u8fd9\u4e2a\u6ce8\u89e3\u7684\u4f5c\u7528\u5c31\u662f\u5411\u9879\u76ee\u4e2d\u5bfc\u5165\u4ec0\u4e48\u4ec0\u4e48\u914d\u7f6e\u7c7b\u7684\u529f\u80fd\uff0c\u5b83\u4f4d\u4e8e spring-context \u5305\u5185\uff0c\u6240\u4ee5\u5b83\u5728\u8fd9\u91cc\u7684\u6240\u7528\u662f\uff0c\u5411\u9879\u76ee\u4e2d\u5bfc\u5165\u4e86 AutoConfigurationImportSelector \u914d\u7f6e\u7c7b\u3002<\/p>\n\n\n\n<p><strong>2.3 AutoConfigurationImportSelector<\/strong><\/p>\n\n\n\n<p>\u5148\u6765\u770b\u770b\u8fd9\u4e2a\u7c7b\u7684\u7ee7\u627f\u5173\u7cfb\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-289-1024x163.png\" alt=\"\" class=\"wp-image-10882\" width=\"447\" height=\"70\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-1024x163.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-300x48.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-768x122.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-1536x244.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-2048x326.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-830x132.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-230x37.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-350x56.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-289-480x76.png 480w\" sizes=\"(max-width: 447px) 100vw, 447px\" \/><\/figure><\/div>\n\n\n\n<p>\u548b\u4e00\u770b\u8fd9\u4e2a\u7c7b\u5b9e\u73b0\u7684\u63a5\u53e3\u8fd8\u633a\u591a\u7684\uff0c\u5176\u5b9e\u5c31<strong>\u4e24\u5927\u7c7b<\/strong>\uff1a<\/p>\n\n\n\n<ol><li>ImportSelector \u7c7b\u63a5\u53e3<\/li><li>Aware \u7c7b\u63a5\u53e3<\/li><\/ol>\n\n\n\n<p>\u5148\u8bf4\u7b2c\u4e00\u7c7b\uff0cAutoConfigurationImportSelector \u5e76\u6ca1\u6709\u76f4\u63a5\u5b9e\u73b0 ImportSelector \u63a5\u53e3\u800c\u662f\u5176\u5b50\u63a5\u53e3 DeferredImportSelector \u63a5\u53e3\uff0c\u90a3\u8fd9\u4e24\u4e2a\u63a5\u53e3\u6709\u4ec0\u4e48\u533a\u522b\u5417\uff1fDeferredImportSelector \u63a5\u53e3\u4f1a\u5728\u6240\u6709\u7684 @Configuration \u7c7b\u52a0\u8f7d\u5b8c\u6210\u4e4b\u540e\u5728\u52a0\u8f7d\u8fd4\u56de\u7684\u914d\u7f6e\u7c7b\uff0c\u800c ImportSelector \u662f\u5728\u52a0\u8f7d\u5b8c @Configuration \u4e4b\u524d\u5148\u53bb\u52a0\u8f7d\u8fd4\u56de\u7684\u914d\u7f6e\u7c7b\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u7c7b\uff0cXXXAware \u7c7b\u63a5\u53e3\u5219\u662f\u5728 Bean \u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u4e3a\u5176\u4f20\u5165\u76f8\u5173\u7684\u73af\u5883\u5bf9\u8c61\uff0c\u5982 BeanFactory \u3001Environment \u3001ResourceLoader \u7b49\u3002<\/p>\n\n\n\n<p>\u5728 Spring \u4e2d\u5b83\u4f1a\u4fdd\u8bc1\u5728\u6267\u884c ImportSelector \u63a5\u53e3\u7684\u65b9\u6cd5\u4e4b\u524d\uff0c\u5148\u6267\u884c XXXAware \u63a5\u53e3\u7684\u65b9\u6cd5\uff0c\u4fdd\u8bc1\u5bf9\u5e94\u7684\u5c5e\u6027\u90fd\u88ab\u9644\u4e0a\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u90a3\u73b0\u5728\u56de\u5230\u63a5\u53e3 <code>ImportSelector<\/code> \u5b83\u662f\u5e72\u4ec0\u4e48\u7684\uff0c\u53c8\u662f\u5728\u4ec0\u4e48\u65f6\u5019\u88ab\u6267\u884c\u7684\u3002<\/p>\n\n\n\n<p>\u63a5\u53e3\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public interface ImportSelector {\n\n    \/\/ \u6839\u636e\u5bfc\u5165\u7684Configuration\u7c7b\u7684\u6ce8\u89e3\u5143\u6570\u636e\u9009\u62e9\u54ea\u4e00\u4e2a\u7c7b\u9700\u8981\u88ab\u5bfc\u5165\uff0c\u8fd4\u56de\u7684\u6570\u7ec4\u5c31\u662f\u9700\u8981\u88ab\u5bfc\u5165\u7684\u7c7b\u540d\n    String[] selectImports(AnnotationMetadata importingClassMetadata);\n    \/\/ \u6392\u9664\u4e0d\u9700\u8981\u5bfc\u5165\u7684\u7c7b\n    @Nullable\n    default Predicate&lt;String> getExclusionFilter() {\n        return null;\n    }\n}\n<\/pre>\n\n\n\n<p>\u63a5\u53e3\u53ea\u662f\u5b9a\u4e49\u4e86\u89c4\u8303\uff0cselectImports \u65b9\u6cd5\u7684\u5177\u4f53\u5b9e\u73b0\u5728 AutoConfigurationImportSelector \u7c7b\u4e2d\uff0c\u6211\u4eec\u6765\u770b\u770b\u5b9e\u73b0\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Override\npublic String[] selectImports(AnnotationMetadata annotationMetadata) {\n    \/\/ \u68c0\u67e5\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u662f\u5426\u5f00\u542f\uff0c\u9ed8\u8ba4\u5f00\u542f\n    if (!isEnabled(annotationMetadata)) {\n        return NO_IMPORTS;\n    }\n    \/\/ \u5c01\u88c5\u5c06\u88ab\u5f15\u5165\u7684\u81ea\u52a8\u914d\u7f6e\u4fe1\u606f\n    AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);\n    \/\/ \u8fd4\u56de\u7b26\u5408\u6761\u4ef6\u7684\u914d\u7f6e\u7c7b\u7684\u5168\u9650\u5b9a\u7c7b\u540d\u6570\u7ec4\n    return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());\n}<\/pre>\n\n\n\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u77e5\u9053 getAutoConfigurationEntry(annotationMetadata) \u65b9\u6cd5\u5c31\u662f\u6211\u4eec\u8981\u6df1\u5165\u7814\u7a76\u7684\u70b9\uff0c\u56e0\u4e3a\u5b83\u8fd4\u56de\u7684\u662f\u6240\u6709\u9700\u8981\u81ea\u52a8\u914d\u7f6e\u7684\u5168\u9650\u5b9a\u7c7b\u540d\uff0c\u53ea\u6709\u628a\u8fd9\u4e2a\u8fd4\u56de\u7ed9\u4e86 SpringBoot \uff0c\u5b83\u624d\u77e5\u9053\u9700\u8981\u81ea\u52a8\u88c5\u914d\u90a3\u4e9b\u529f\u80fd\u3002<\/p>\n\n\n\n<p><strong>\u81f3\u4e8e\u4f55\u65f6\u6267\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4e5f\u662f Debug \u7684\u65f6\u5019\u624d\u641e\u660e\u767d\u4e2a\u6240\u4ee5\u7136<\/strong>\u3002<\/p>\n\n\n\n<p>\u8fd8\u8bb0\u5f97\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u7684 ImportSelector \u548c DeferredImportSelector \u7684\u533a\u522b\u5417\uff1f\u56e0\u4e3a\u6211\u4eec\u7684 AutoConfigurationImportSelector \u7c7b\u5b9e\u73b0\u7684\u662f\u540e\u8005\uff0c\u6240\u4ee5\u7a0b\u5e8f\u5728\u6267\u884c\u7684\u65f6\u5019\u4e0d\u4f1a\u53bb\u6267\u884c selectImports \u65b9\u6cd5\uff0c\u800c\u662f\u4f1a\u53bb\u6267\u884c\u5176\u9759\u6001\u5185\u90e8\u7c7b AutoConfigurationGroup \u4e2d\u7684 <code>process<\/code> \u65b9\u6cd5\u5e76\u4e14\u6700\u7ec8\u4f1a\u8c03\u5230 getAutoConfigurationEntry \u65b9\u6cd5\u83b7\u53d6\u5230\u6240\u6709\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u3002<\/p>\n\n\n\n<p>\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u662f\u4ece org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.AutoConfigurationGroup # process \u8c03\u8fdb\u6765\uff0c\u5728\u8fd9\u91cc\u4e0d\u505a\u8fc7\u591a\u7684\u5206\u6790\uff0c\u4e0d\u662f\u672c\u6b21\u7684\u91cd\u70b9\uff0c\u4e0b\u9762\u5206\u6790\u81ea\u52a8\u88c5\u914d\u7684\u7c7b\u662f\u5982\u4f55\u88ab\u52a0\u8f7d\u8fdb\u6765\u7684\u3002<\/p>\n\n\n\n<p><strong>2.3.1 getAutoConfigurationEntry<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {\n    \/\/ \u662f\u5426\u5f00\u542f\u81ea\u52a8\u88c5\u914d\n    if (!isEnabled(annotationMetadata)) {\n        \/\/ \u672a\u5f00\u542f\uff0c\u8fd4\u56de\u7a7a\n        return EMPTY_ENTRY;\n    }\n    AnnotationAttributes attributes = getAttributes(annotationMetadata);\n    \/\/ \u901a\u8fc7 SpringFactoriesLoader \u7c7b\u63d0\u4f9b\u7684\u65b9\u6cd5\u52a0\u8f7d\u7c7b\u8def\u5f84\u4e2d META-INF \u76ee\u5f55\u4e0b\u7684 spring.factories \u6587\u4ef6\u4e2d\u9488\u5bf9 EnableAutoConfiguration \u7684\u6ce8\u518c\u914d\u7f6e\u7c7b\n    List&lt;String> configurations = getCandidateConfigurations(annotationMetadata, attributes);\n    \/\/ \u961f\u83b7\u5f97\u7684\u6ce8\u518c\u914d\u7f6e\u7c7b\u96c6\u5408\u8fdb\u884c\u53bb\u91cd\u5904\u7406\uff0c\u9632\u6b62\u591a\u4e2a\u9879\u76ee\u5f15\u5165\u540c\u6837\u7684\u914d\u7f6e\u7c7b\n    configurations = removeDuplicates(configurations);\n    \/\/ \u83b7\u5f97\u6ce8\u89e3\u4e2d\u88ab exclude \u6216 excludeName \u6240\u6d3e\u51fa\u7684\u7c7b\u7684\u96c6\u5408\n    Set&lt;String> exclusions = getExclusions(annotationMetadata, attributes);\n    \/\/ \u68c0\u67e5\u88ab\u6392\u9664\u7c7b\u662f\u5426\u53ef\u5b9e\u4f8b\u5316\uff0c\u662f\u5426\u88ab\u81ea\u52a8\u6ce8\u518c\u914d\u7f6e\u6240\u4f7f\u7528\uff0c\u4e0d\u7b26\u5408\u6761\u4ef6\u5219\u629b\u51fa\u5f02\u5e38\n    checkExcludedClasses(configurations, exclusions);\n    \/\/ \u4ece\u81ea\u52a8\u914d\u7f6e\u7c7b\u96c6\u5408\u4e2d\u53d6\u51fa\u88ab\u6392\u9664\u7684\u7c7b\n    configurations.removeAll(exclusions);\n    \/\/ \u68c0\u67e5\u914d\u7f6e\u7c7b\u7684\u6ce8\u89e3\u662f\u5426\u7b26\u5408 spring.factories \u6587\u4ef6\u4e2d AutoConfigurationImportFilter \u6307\u5b9a\u7684\u6ce8\u89e3\u68c0\u67e5\u6761\u4ef6\n    configurations = getConfigurationClassFilter().filter(configurations);\n    \/\/ \u5c06\u8d5b\u9009\u5b8c\u6210\u7684\u914d\u7f6e\u7c7b\u548c\u6392\u67e5\u7684\u914d\u7f6e\u7c7b\u6784\u5efa\u4e3a\u4e8b\u4ef6\u7c7b\uff0c\u5e76\u4f20\u5165\u76d1\u542c\u5668\u3002\u76d1\u542c\u5668\u7684\u914d\u7f6e\u5728\u4e8e spring.factories \u6587\u4ef6\u4e2d\uff0c\u901a\u8fc7 AutoConfigurationImportListener z\n    fireAutoConfigurationImportEvents(configurations, exclusions);\n    return new AutoConfigurationEntry(configurations, exclusions);\n}\n<\/pre>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u6bb5\u4ee3\u7801\u6ce8\u91ca\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u6574\u4f53\u4e0a\u4e86\u89e3\u83b7\u53d6\u81ea\u52a8\u88c5\u914d\u7c7b\u7684\u6982\u51b5\u53ca\u64cd\u4f5c\u6d41\u7a0b\uff0c\u4e0b\u9762\u6211\u4f1a\u5bf9\u8fd9\u4e9b\u6d41\u7a0b\u505a\u7ec6\u81f4\u7684\u5206\u6790\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u81ea\u52a8\u88c5\u914d\u5f00\u5173\u529f\u80fd\uff0c\u5f88\u597d\u7406\u89e3\uff0cSpringBoot \u7ed9\u6211\u4eec\u9884\u7559\u4e86 <code>spring.boot.enableautoconfiguration = true\/false<\/code> \u8fd9\u4e00\u914d\u7f6e\u9879\u6765\u63a7\u5236\u662f\u5426\u5f00\u542f\u81ea\u52a8\u88c5\u914d\u529f\u80fd\uff0c\u9ed8\u8ba4\u662f\u5f00\u542f\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6765\u5230\u8fd9\u884c\u4ee3\u7801\uff1a<code>getAttributes(annotationMetadata)<\/code><\/p>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u7684\u4f5c\u7528\u5c31\u662f\u83b7\u53d6\u5230\u4e3b\u7c7b\u4e2d\u914d\u7f6e\u7684 exclude \u3001 excludeName \u4e24\u4e2a\u5c5e\u6027\u7684\u503c\uff0c\u4e3a\u4e86\u5bf9\u540e\u9762\u8bfb\u51fa\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u505a\u6392\u9664\u4f5c\u7528\uff0c\u6392\u9664\u8fd9\u4e9b\u6307\u5b9a\u4e0d\u9700\u8981\u88c5\u914d\u7684\u7c7b\u3002<\/p>\n\n\n\n<p>\u7ee7\u7eed\u5206\u6790\u8fd9\u884c\u4ee3\u7801\uff1a<code>getCandidateConfigurations(annotationMetadata, attributes)<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected List&lt;String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {\n    \/\/ \u91cd\u70b9\uff0c\u83b7\u53d6 META-INF\/spring.factories \u6587\u4ef6\u4e2d EnableAutoConfiguration \u7c7b\u578b\u7684\u503c\n    List&lt;String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),\n                                                                         getBeanClassLoader());\n    Assert.notEmpty(configurations, \"No auto configuration classes found in META-INF\/spring.factories. If you \"\n                    + \"are using a custom packaging, make sure that file is correct.\");\n    return configurations;\n}\n<\/pre>\n\n\n\n<p><strong>SpringFactoriesLoader \u662f Spring-Core \u63d0\u4f9b\u7684\u4e00\u4e2a\u5de5\u5177\u7c7b<\/strong>\uff0c\u5b83\u662f\u4e13\u95e8\u8bfb\u53d6 META-INF\/spring.factories \u6587\u4ef6\u4e2d\u76f8\u5173\u503c\u5f97\u529f\u80fd\uff0c\u6bd4\u5982 loadFactoryNames \u65b9\u6cd5\uff0c\u5982\u679c\u5411\u5176\u4f20\u5165 EnableAutoConfiguration. Class \u7c7b\u578b\u7684\u503c\uff0c\u90a3\u5b83\u5c31\u4f1a\u8bfb\u53d6\u4e0b\u9762\u8fd9\u90e8\u5206\u7684\u503c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"403\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-291-1024x403.png\" alt=\"\" class=\"wp-image-10884\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-1024x403.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-300x118.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-768x302.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-1536x604.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-2048x806.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-830x327.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-230x90.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-350x138.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-291-480x189.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u91cc\u8bf4\u660e\u4e00\u70b9\u7684\u662f\uff0c\u5b83\u4f1a\u8bfb\u53d6\u6240\u6709\u4f9d\u8d56\u5305\u4e0b META-INF\/spring.factories \u6587\u4ef6\u7684\u503c\uff0c\u5982\u679c\u5927\u5bb6 Debug \u7684\u8bdd\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u81ea\u5b9a\u4e49 starter \u4e2d\u81ea\u52a8\u88c5\u914d\u7c7b\u4e5f\u662f\u88ab\u52a0\u8f7d\u8fdb\u6765\u4e86\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"307\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-290-1024x307.png\" alt=\"\" class=\"wp-image-10883\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-1024x307.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-300x90.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-768x230.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-1536x461.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-2048x614.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-830x249.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-230x69.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-350x105.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-290-480x144.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><code>\u6ce8\u610f\uff1aloadFactoryNames \u65b9\u6cd5\u662f\u6839\u636e\u4f20\u5165\u7684\u7c7b\u578b\u53bb\u8bfb\u53d6\u5bf9\u5e94\u7684\u503c\uff0c\u6240\u4ee5\u5728\u8bfb\u53d6 spring.factories \u6587\u4ef6\u503c\u65f6\uff0c\u5b83\u662f\u4e00\u4e2a\u901a\u7528\u65b9\u6cd5\u3002<\/code><\/p>\n\n\n\n<p>\u4e0b\u9762\u63a5\u7740\u5206\u6790\u8fd9\u4e2a\u65b9\u6cd5\uff1a<code>removeDuplicates(configurations)<\/code><\/p>\n\n\n\n<p>\u8fd9\u53e5\u4ee3\u7801\u975e\u5e38\u7b80\u5355\uff0c\u6211\u662f\u4e0d\u60f3\u8d34\u4ee3\u7801\u4e86\u3002\u5b83\u7684\u4f5c\u7528\u662f\u53bb\u91cd\uff0c\u56e0\u4e3a getCandidateConfigurations \u662f\u52a0\u8f7d\u6240\u7528\u4f9d\u8d56\u5305\u4e0b\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\uff0c\u96be\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u5305\u4e0d\u4f1a\u5f15\u5165\u91cd\u590d\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u5c06\u91cd\u590d\u7684\u7c7b\u8fdb\u884c\u6392\u9664\u3002\u6392\u9664\u65b9\u6cd5\u4e5f\u662f\u5f88\u7b80\u5355\uff0c\u4f7f\u7528 Set \u7ed3\u6784\u7684\u7279\u6027\u8fdb\u884c\u6392\u9664\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\u770b\u4e0b\u9762\u8fd9\u4e2a\u65b9\u6cd5\uff1a<code>getExclusions(annotationMetadata, attributes)<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected Set&lt;String> getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) {\n   Set&lt;String> excluded = new LinkedHashSet&lt;>();\n    \/\/ \u6392\u9664\u914d\u7f6e\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\n   excluded.addAll(asList(attributes, \"exclude\"));\n   excluded.addAll(Arrays.asList(attributes.getStringArray(\"excludeName\")));\n    \/\/ \u6392\u9664\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6 spring.autoconfigure.exclude = \u7c7b\uff0c\u7684\u65b9\u6cd5\u8fdb\u884c\u6392\u9664\n   excluded.addAll(getExcludeAutoConfigurationsProperty());\n   return excluded;<\/pre>\n\n\n\n<p>\u4e0a\u9762\u8bf4\u8fc7 attributes \u662f\u4e3b\u7c7b\u4e2d\u914d\u7f6e\u7684\u9700\u8981\u79fb\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\uff0c\u800c getExcludeAutoConfigurationsProperty \u5219\u662f\u901a\u8fc7 <code>spring.autoconfigure.exclude = \u5168\u9650\u5b9a\u7c7b\u540d<\/code> \u7684\u65b9\u5f0f\u6392\u9664\uff0c\u6240\u4ee5\u8fd9\u4e2a\u65b9\u6cd5\u7684\u4f5c\u7528\u5c31\u662f\u8fd4\u56de\u4e3b\u7c7b\u4e2d\u914d\u7f6e\u7684\u548c spring.autoconfigure.exclude \u914d\u7f6e\u7684\u9700\u8981\u6392\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u3002<\/p>\n\n\n\n<p>\u5728\u83b7\u53d6\u4e86\u9700\u8981\u6392\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u4e4b\u540e\u5219\u662f\u9700\u8981\u5bf9\u8fd9\u4e9b\u6392\u9664\u7c7b\u8fdb\u884c\u68c0\u67e5\uff0c\u68c0\u67e5\u6392\u9664\u7684\u7c7b\u662f\u5426\u5c5e\u4e8e\u5f53\u524d ClassLoad \u548c\u4e0d\u5b58\u5728\u4e8e\u9700\u8981\u81ea\u52a8\u88c5\u914d\u7c7b\u7684\u96c6\u5408\u4e2d\uff0c\u5982\u679c\u6761\u4ef6\u6ee1\u8db3\uff0c\u90a3\u5c31\u8981\u62a5\u9519\u4e86\u3002<\/p>\n\n\n\n<p>\u68c0\u67e5\u901a\u8fc7\u540e\uff0c\u5c31\u662f\u6392\u9664\u4e86\uff0c\u4ee3\u7801\u4f53\u73b0\u662f\u8fd9\u4e2a\uff1a<code>configurations.removeAll(exclusions)<\/code> \uff0c\u5e38\u89c4\u7684\u96c6\u5408\u64cd\u4f5c\uff0c\u5c31\u4e0d\u8fc7\u591a\u8bb2\u4e86\u3002<\/p>\n\n\n\n<p>\u81f3\u6b64\u5462\uff0c\u81ea\u52a8\u88c5\u914d\u7684\u521d\u6b65\u529f\u80fd\u7b97\u662f\u5b8c\u6210\u4e86\uff0c\u6211\u603b\u7ed3\u4e00\u4e0b\u521d\u6b65\u529f\u80fd\u5e72\u4e86\u4e9b\u5565\uff1a<\/p>\n\n\n\n<ol><li>\u5224\u65ad\u662f\u5426\u9700\u8981\u81ea\u52a8\u88c5\u914d<\/li><li>\u52a0\u8f7d\u6240\u6709\u5305\u4e0b\u7684 META-INF\/spring.factories \u6587\u4ef6\u4e2d EnableAutoConfiguration. Class \u7c7b\u578b\u7684\u503c<\/li><li>\u83b7\u53d6\u9700\u8981\u6392\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u96c6\u5408<\/li><li>\u68c0\u67e5\u9700\u8981\u6392\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u662f\u5426\u7b26\u5408\u6392\u9664\u8981\u6c42<\/li><li>\u5bf9\u52a0\u8f7d\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u96c6\u5408\u8fdb\u884c\u6392\u9664<\/li><\/ol>\n\n\n\n<p>SpringBoot \u540e\u7eed\u8fd8\u8981\u5224\u65ad\u90a3\u4e9b\u81ea\u52a8\u88c5\u914d\u7684\u7c7b\u9700\u8981\u8d77\u4f5c\u7528\uff0c\u603b\u4e0d\u81f3\u4e8e\u6240\u6709\u7684\u914d\u7f6e\u90fd\u751f\u6548\u5427\uff01\u6240\u4ee5\u5f80\u4e0b\u770b\u3002<\/p>\n\n\n\n<p><strong>2.4 \u8fc7\u6ee4\u81ea\u52a8\u88c5\u914d<\/strong><\/p>\n\n\n\n<p>\u6b63\u5982\u4e0a\u9762\u8bf4\u7684\u90a3\u6837\uff0c\u52a0\u8f7d\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u4e0d\u53ef\u80fd\u5168\u90e8\u90fd\u751f\u6548\uff0c\u6240\u4ee5\u8981\u5728\u4e0b\u9762\u8fd9\u884c\u4ee3\u7801\u5904\u8fdb\u884c\u8fc7\u6ee4\uff0c\u5c06\u90a3\u4e9b\u4e0d\u9700\u8981\u751f\u6548\u7684\u81ea\u52a8\u88c5\u914d\u5254\u9664\u6389\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">configurations = getConfigurationClassFilter().filter(configurations);<\/pre>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u5206\u4e3a\u4e24\u90e8\u5206\uff1a<\/p>\n\n\n\n<ol><li>\u83b7\u53d6\u8fc7\u6ee4\u5668<\/li><li>\u6267\u884c\u8fc7\u6ee4\u5668\u7684\u8fc7\u6ee4\u65b9\u6cd5<\/li><\/ol>\n\n\n\n<p>\u5148\u6765\u8bf4\u8bf4\u7b2c\u4e00\u90e8\u5206\uff0cgetConfigurationClassFilter() \u65b9\u6cd5\u4e3b\u8981\u662f\u83b7\u53d6 META-INF\/spring.factories \u6587\u4ef6\u4e2d\u914d\u7f6e\u4e86 key \u4e3a <code>org.springframework.boot.autoconfigure.AutoConfigurationImportFilter<\/code> \u7684\u503c\uff0c\u5e76\u5c01\u88c5\u6210 ConfigurationClassFilter \u5bf9\u8c61\u8fd4\u56de\u51fa\u53bb\uff0c\u6e90\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private ConfigurationClassFilter getConfigurationClassFilter() {\n    if (this.configurationClassFilter == null) {\n        \/\/ \u52a0\u8f7d\u6587\u4ef6\u4e2d\u7684\u8fc7\u6ee4\u5668\n        List&lt;AutoConfigurationImportFilter> filters = getAutoConfigurationImportFilters();\n        for (AutoConfigurationImportFilter filter : filters) {\n            \/\/ \u7ed9\u8fc7\u6ee4\u5668\u914d\u7f6e\u76f8\u5e94\u7684\u73af\u5883\u5c5e\u6027\u503c\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u662f\u521d\u59cb\u5316\u8fc7\u6ee4\u5668\u7684\u4e00\u4e9b\u5c5e\u6027\u503c\n            invokeAwareMethods(filter);\n        }\n        \/\/ \u5c01\u88c5\u8fc7\u6ee4\u5668\u914d\u7f6e\u5bf9\u8c61\n        this.configurationClassFilter = new ConfigurationClassFilter(this.beanClassLoader, filters);\n    }\n    return this.configurationClassFilter;\n}\n\/\/ \u5177\u4f53\u7684\u52a0\u8f7d META-INF\/spring.factories \u4e2d\u7684 AutoConfigurationImportFilter \u503c\nprotected List&lt;AutoConfigurationImportFilter> getAutoConfigurationImportFilters() {\n    return SpringFactoriesLoader.loadFactories(AutoConfigurationImportFilter.class, this.beanClassLoader);\n}\n<\/pre>\n\n\n\n<p>\u5982\u56fe\uff0cSpringFactoriesLoader.loadFactories(AutoConfigurationImportFilter.class, this.beanClassLoader) \u83b7\u53d6\u7684\u662f\u6587\u4ef6\u4e2d\u8fd9\u90e8\u5206\u7684\u503c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-292-1024x188.png\" alt=\"\" class=\"wp-image-10885\" width=\"479\" height=\"88\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-1024x188.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-300x55.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-768x141.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-830x152.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-230x42.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-350x64.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292-480x88.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-292.png 1154w\" sizes=\"(max-width: 479px) 100vw, 479px\" \/><\/figure><\/div>\n\n\n\n<p>\u518d\u6765\u8bf4\u8bf4\u7b2c\u4e8c\u90e8\u5206\uff0c\u5728\u7b2c\u4e00\u90e8\u5206\u4e2d\u83b7\u53d6\u4e86\u6240\u6709\u7684\u8fc7\u6ee4\u5668\u4e4b\u540e\u7ed9\u6211\u4eec\u8fd4\u56de\u4e86 ConfigurationClassFilter \u5bf9\u8c61\uff0c\u7136\u540e\u5728\u8c03\u7528\u4ed6\u7684 filter \u65b9\u6cd5\u8fdb\u884c\u8fc7\u6ee4\u7684\uff0c\u90a3\u6211\u4eec\u5c31\u6765\u770b\u770b\u8fd9\u4e2a\u65b9\u6cd5\u7684\u6e90\u7801\u3002<\/p>\n\n\n\n<p>org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.ConfigurationClassFilter # filter<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">List&lt;String> filter(List&lt;String> configurations) {\n    long startTime = System.nanoTime();\n    \/\/ \u5c06\u6240\u6709\u52a0\u8f7d\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\u5c01\u88c5\u6210\u6570\u7ec4\n    String[] candidates = StringUtils.toStringArray(configurations);\n    boolean skipped = false;\n    \/\/ \u6328\u4e2a\u904d\u5386\u8fc7\u6ee4\u5668\u8fdb\u884c\u5224\u65ad\uff0c\u81ea\u52a8\u88c5\u914d\u662f\u5426\u751f\u6548\n    for (AutoConfigurationImportFilter filter : this.filters) {\n        \/\/ \u8fd9\u662f\u5224\u65ad\u751f\u6548\u903b\u8f91\uff0ccandidates \u662f\u81ea\u52a8\u88c5\u914d\u7c7b\u6570\u7ec4\uff0cthis.autoConfigurationMetadata \u8fd9\u4e2a\u662f META-INF\/spring-autoconfigure-metadata.properties \u6587\u4ef6\u4e2d\u7684\u503c\n        boolean[] match = filter.match(candidates, this.autoConfigurationMetadata);\n        for (int i = 0; i &lt; match.length; i++) {\n            if (!match[i]) {\n                \/\/ \u5c06\u4e0d\u751f\u6548\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\u66ff\u6362\u4e3a null \u503c\n                candidates[i] = null;\n                \/\/ \u8fd9\u4e2a\u662f\u4e00\u4e2a\u6807\u5fd7\u4f4d\uff0c\u4fdd\u8bc1\u4e0b\u9762\u9700\u8981\u8fdb\u884c\u5254\u9664\n                skipped = true;\n            }\n        }\n    }\n    \/\/ \u5224\u65ad\u6807\u5fd7\u4f4d\uff0c\u6709\u6539\u52a8\uff0c\u8bf4\u660e\u8981\u5f80\u4e0b\u8d70\uff0c\u5982\u679c\u6ca1\u6709\u6539\u52a8\u90a3\u5c31\u5168\u90e8\u751f\u6548\uff0c\u4e0d\u8fdb\u884c\u5254\u9664\n    if (!skipped) {\n        return configurations;\n    }\n    \/\/ \u5254\u9664\u64cd\u4f5c\n    List&lt;String> result = new ArrayList&lt;>(candidates.length);\n    \/\/ \u904d\u5386\u6240\u6709\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u6570\u7ec4\n    for (String candidate : candidates) {\n        \/\/ \u5c06\u4e0d\u4e3a null \u7684\u503c\u8fd4\u56de\u51fa\u53bb\n        if (candidate != null) {\n            result.add(candidate);\n        }\n    }\n    if (logger.isTraceEnabled()) {\n        int numberFiltered = configurations.size() - result.size();\n        logger.trace(\"Filtered \" + numberFiltered + \" auto configuration class in \"\n                     + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + \" ms\");\n    }\n    \/\/ \u6700\u7ec8\u9700\u8981\u81ea\u52a8\u88c5\u914d\u7c7b\u7684\u96c6\u5408\n    return result;\n}<\/pre>\n\n\n\n<p><code>\u8fd9\u4e00\u6bb5\u662f\u5224\u65ad\u81ea\u52a8\u88c5\u914d\u7c7b\u662f\u5426\u751f\u6548\u7684\u6838\u5fc3\u4ee3\u7801\uff0c\u800c\u4e3b\u8981\u7684\u5224\u65ad\u903b\u8f91\u5219\u662f match \u65b9\u6cd5<\/code>\u3002<\/p>\n\n\n\n<p>\u4ece\u4ee3\u7801\u6211\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8c03\u7528\u7684\u662f AutoConfigurationImportFilter \u7c7b\u7684 match \u65b9\u6cd5\uff0c\u90a3\u6211\u4eec\u6765\u770b\u770b\u5b83\u7684\u7c7b\u7ee7\u627f\u7ed3\u6784\u56fe\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-293-1024x301.png\" alt=\"\" class=\"wp-image-10886\" width=\"503\" height=\"147\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-1024x301.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-300x88.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-768x226.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-1536x452.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-2048x603.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-830x244.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-230x68.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-350x103.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-293-480x141.png 480w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/figure><\/div>\n\n\n\n<ul><li>AutoConfigurationImportFilter \uff1a\u5b9a\u4e49\u4e86 match \u65b9\u6cd5\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\u3002<\/li><li>FilteringSpringBootCondition \uff1a match \u65b9\u6cd5\u7684\u76f4\u63a5\u5b9e\u73b0\u7c7b\u3002<\/li><li>OnBeanCondition \uff1a\u5177\u4f53\u8fc7\u6ee4\u5668\uff0c\u5176\u5b9e match \u4e2d\u4f1a\u8c03\u7528\u6bcf\u4e2a\u5177\u4f53\u8fc7\u6ee4\u5668\u4e2d\u7684 getOutcomes \u65b9\u6cd5\u5224\u65ad\u751f\u6548\u903b\u8f91\u3002<\/li><li>OnClassCondition \uff1a\u5177\u4f53\u8fc7\u6ee4\u5668\uff0c\u5176\u5b9e match \u4e2d\u4f1a\u8c03\u7528\u6bcf\u4e2a\u5177\u4f53\u8fc7\u6ee4\u5668\u4e2d\u7684 getOutcomes \u65b9\u6cd5\u5224\u65ad\u751f\u6548\u903b\u8f91\u3002<\/li><li>OnWebApplicationCondition \uff1a\u5177\u4f53\u8fc7\u6ee4\u5668\uff0c\u5176\u5b9e match \u4e2d\u4f1a\u8c03\u7528\u6bcf\u4e2a\u5177\u4f53\u8fc7\u6ee4\u5668\u4e2d\u7684 getOutcomes \u65b9\u6cd5\u5224\u65ad\u751f\u6548\u903b\u8f91\u3002<\/li><\/ul>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053 match \u662f\u88ab getConfigurationClassFilter \u65b9\u6cd5\u52a0\u8f7d\u51fa\u6765\u7684\u5177\u4f53\u8fc7\u6ee4\u5668\u8fdb\u884c\u8c03\u7528\u7684\uff0c\u518d\u7ed3\u5408\u4e0a\u9762\u6211\u4ecb\u7ecd AutoConfigurationImportFilter \u7c7b\u7ed3\u6784\u4f53\u53ef\u77e5\uff0c\u6700\u7ec8\u5224\u65ad\u751f\u6548\u7684\u903b\u8f91\u51fa\u81ea\u8fc7\u6ee4\u5668\u4e2d\u7684 getOutcomes \u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u6bcf\u4e2a\u8fc7\u6ee4\u5668\u90fd\u6709\u5bf9\u5e94\u7684 getOutcomes \u5904\u7406\u903b\u8f91\uff0c\u6240\u4ee5\u5c31\u4e0d\u8d34\u8fd9\u4e2a\u65b9\u6cd5\u7684\u4ee3\u7801\u4e86\uff0c\u4f46\u4e07\u53d8\u4e0d\u79bb\u5176\u5b97\uff0c\u6240\u6709\u7684\u5904\u7406\u903b\u8f91\u90fd\u662f\u901a\u8fc7\u5224\u65ad\u81ea\u52a8\u88c5\u914d\u7c7b + \u201d.\u201c + OnBeanCondition \u6216 OnClassCondition \u6216 OnWebApplicationCondition \u5f62\u6210 key \u53bb this.autoConfigurationMetadata \u96c6\u5408\u4e2d\u627e\u5bf9\u5e94\u7684\u503c\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\u5219\u9ed8\u8ba4\u52a0\u8f7d\u53cd\u4e4b\u5219\u5c06\u83b7\u53d6\u5230\u7684\u503c\u901a\u8fc7\u52a0\u8f7d\u5668\u8fdb\u884c\u52a0\u8f7d\uff0c\u52a0\u8f7d\u6210\u529f\u5219\u81ea\u52a8\u88c5\u914d\u7c7b\u751f\u6548\u53cd\u4e4b\u5219\u4e0d\u751f\u6548\u8fc7\u6ee4\u6389\uff0c\u6700\u7ec8\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5bf9\u5e94\u81ea\u52a8\u88c5\u914d\u7c7b\u96c6\u5408\u7684 true \/ false \u6570\u7ec4\u3002<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u7684 match \u65b9\u6cd5\u5c31\u5206\u6790\u7ed3\u675f\u4e86\uff0c\u5b83\u6700\u7ec8\u8fd4\u56de\u7684\u662f\u548c\u81ea\u52a8\u88c5\u914d\u7c7b\u96c6\u5408\u5bf9\u5e94\u7684 true \/ false \u96c6\u5408\uff0c\u5bf9\u5e94\u4f4d\u7f6e\u7684\u503c\u4e3a true \u8bf4\u660e\u81ea\u52a8\u88c5\u914d\u7c7b\u96c6\u5408\u4e2d\u5bf9\u5e94\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u751f\u6548<\/p>\n\n\n\n<p><strong>2.5 \u4e8b\u4ef6\u5c01\u88c5\u548c\u5e7f\u64ad<\/strong><\/p>\n\n\n\n<p>\u4e0a\u9762\u6211\u4eec\u5df2\u7ecf\u5206\u6790\u51fa\u4e86\u81ea\u52a8\u88c5\u914d\u9700\u8981\u751f\u6548\u7684\u81ea\u52a8\u88c5\u914d\u5168\u9650\u5b9a\u7c7b\u540d\u96c6\u5408\u4e86\uff0c\u4f46\u8fd8\u6ca1\u5b8c\u5462\uff01<\/p>\n\n\n\n<p>getAutoConfigurationEntry \u65b9\u6cd5\u8fd8\u6709\u6700\u540e\u4e00\u884c\u4ee3\u7801\uff1afireAutoConfigurationImportEvents(configurations, exclusions) \u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6765\u770b\u770b\u5b83\u7684\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private void fireAutoConfigurationImportEvents(List&lt;String> configurations, Set&lt;String> exclusions) {\n    \/\/ \u52a0\u8f7d META-INF\/spring.factories \u6587\u4ef6\u4e2d\u7c7b\u578b\u4e3a AutoConfigurationImportListener \u7684\u76d1\u542c\u5668\uff0c\n    List&lt;AutoConfigurationImportListener> listeners = getAutoConfigurationImportListeners();\n    if (!listeners.isEmpty()) {\n        \/\/ \u5c01\u88c5\u81ea\u52a8\u88c5\u914d\u5bfc\u5165\u4e8b\u4ef6\uff0cAutoConfigurationImportEvent\n        AutoConfigurationImportEvent event = new AutoConfigurationImportEvent(this, configurations, exclusions);\n        \/\/ \u904d\u5386\u76d1\u542c\u5668\n        for (AutoConfigurationImportListener listener : listeners) {\n            invokeAwareMethods(listener);\n            \/\/ \u5e7f\u64ad\u4e8b\u4ef6\uff0c\u6240\u6709\u76d1\u542c AutoConfigurationImportEvent \u4e8b\u4ef6\u7684\u90fd\u4f1a\u505a\u51fa\u76f8\u5173\u7684\u53cd\u5e94\n            listener.onAutoConfigurationImportEvent(event);\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u4e8b\u4ef6\u76d1\u542c\u548c\u5e7f\u64ad\u4e0d\u662f\u6211\u4eec\u5206\u6790\u7684\u91cd\u70b9\uff0c\u800c\u8fd9\u91cc\u518d\u52a0\u8f7d\u5b8c\u81ea\u52a8\u914d\u7f6e\u7c7b\u4e4b\u540e\u5c31\u662f\u505a\u4e86\u4e00\u4e2a\u4e8b\u4ef6\u5e7f\u64ad\u3002\u5c06\u751f\u6548\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\u548c\u88ab\u6392\u9664\u7684\u81ea\u52a8\u88c5\u914d\u7c7b\u5c01\u88c5\u6210\u4e8b\u4ef6\u5411\u5916\u5e7f\u64ad\uff0c\u5f53\u9047\u5230\u5bf9\u8fd9\u4ef6\u4e8b\u611f\u5174\u8da3\u7684\u76d1\u542c\u5668\u5c31\u4f1a\u505a\u51fa\u76f8\u5173\u7684\u53cd\u5e94\u3002<\/p>\n\n\n\n<p>META-INF\/spring.factories \u6587\u4ef6\u4e2d\u7c7b\u578b\u4e3a AutoConfigurationImportListener \u7684\u76d1\u542c\u5668\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-294-1024x161.png\" alt=\"\" class=\"wp-image-10887\" width=\"566\" height=\"89\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-1024x161.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-300x47.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-768x120.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-1536x241.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-830x130.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-230x36.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-350x55.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294-480x75.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-294.png 2040w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3\u3001\u6700\u540e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5bf9\u4e8e SpringBoot \u7684\u81ea\u52a8\u88c5\u914d\u6211\u7531\u6d45\u5165\u6df1\u7684\u5206\u6790\u4e86\u5176\u6574\u4e2a\u7684\u8fd0\u884c\u6d41\u7a0b\uff0c\u6574\u4f53\u6765\u8bf4\u504f\u5411\u7b80\u5355\u6ca1\u6709\u6666\u6da9\u96be\u61c2\u7684\u4ee3\u7801\u3002\u5927\u5bb6\u53ef\u4ee5\u5bf9\u7740\u672c\u7bc7\u8bb2\u89e3\u7684\u6b65\u9aa4\u81ea\u5df1\u624b\u52a8 Debug \u51e0\u6b21\u76f8\u4fe1\u638c\u63e1\u5b83\u4e0d\u6210\u95ee\u9898\uff0c\u6700\u540e\u9644\u4e0a\u81ea\u52a8\u88c5\u914d\u6838\u5fc3\u4ee3\u7801\u7684\u5904\u7406\u903b\u8f91\u6d41\u7a0b\u56fe\uff0c\u4fbf\u4e8e\u6574\u4f53\u7406\u89e3\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-295-1024x727.png\" alt=\"\" class=\"wp-image-10888\" width=\"452\" height=\"321\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-1024x727.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-300x213.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-768x545.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-1536x1090.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-2048x1453.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-830x589.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-230x163.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-350x248.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-295-480x341.png 480w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e00\u65e5\u6211\u5728\u6109\u5feb\u5f97\u9068\u6e38\u65f6\uff0c\u770b\u5230\u6709\u9c7c\u53cb\u5728\u95ee\uff1aSpringBoot \u4e2d\u5f15\u5165\u4e86 Nacos \u4f9d\u8d56\u4e3a\u5565\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10879"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10879"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10879\/revisions"}],"predecessor-version":[{"id":10889,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10879\/revisions\/10889"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}