{"id":10007037,"date":"2023-01-03T17:27:15","date_gmt":"2023-01-03T09:27:15","guid":{"rendered":"https:\/\/ityet.com\/?p=10007037"},"modified":"2023-01-03T17:27:15","modified_gmt":"2023-01-03T09:27:15","slug":"%e6%89%8b%e6%8a%8a%e6%89%8b%e5%b8%a6%e4%bd%a0%e5%bc%80%e5%8f%91starter%ef%bc%8c%e7%82%b9%e5%af%b9%e7%82%b9%e5%b8%a6%e4%bd%a0%e8%ae%b2%e8%a7%a3%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10007037","title":{"rendered":"\u624b\u628a\u624b\u5e26\u4f60\u5f00\u53d1starter\uff0c\u70b9\u5bf9\u70b9\u5e26\u4f60\u8bb2\u89e3\u539f\u7406"},"content":{"rendered":"<h6>\u4eac\u4e1c\u7269\u6d41 \u5b54\u7965\u4e1c<\/h6>\n<pre><code>\n   _____            _             ____              _   \n  \/ ____|          (_)           |  _ \/            | |  \n | (___  _ __  _ __ _ _ __   __ _| |_) | ___   ___ | |_ \n  ___ | '_ | '__| | '_ \/ \/ _` |  _ &lt; \/ _ \/ \/ _ | __|\n  ____) | |_) | |  | | | | | (_| | |_) | (_) | (_) | |_ \n |_____\/| .__\/|_|  |_|_| |_|__, |____\/ ___\/ ___\/ __|\n        | |                  __\/ |                      \n        |_|                 |___\/                       <\/code><\/pre>\n<h2>1.  \u4e3a\u4ec0\u4e48\u8981\u7528Starter?<\/h2>\n<ul>\n<li>\u73b0\u5728\u6211\u4eec\u5c31\u6765\u56de\u5fc6\u4e00\u4e0b\uff0c\u5728\u8fd8\u6ca1\u6709Spring-boot\u6846\u67b6\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f7f\u7528Spring \u5f00\u53d1\u9879\u76ee\uff0c\u5982\u679c\u9700\u8981\u67d0\u4e00\u4e2a\u6846\u67b6\uff0c\u4f8b\u5982mybatis\uff0c\u6211\u4eec\u7684\u6b65\u9aa4\u4e00\u822c\u90fd\u662f\uff1a<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u5230maven\u4ed3\u5e93\u53bb\u627e\u9700\u8981\u5f15\u5165\u7684mybatis jar\u5305\uff0c\u9009\u53d6\u5408\u9002\u7684\u7248\u672c\uff08\u6613\u53d1\u751f\u51b2\u7a81\uff09<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u5230maven\u4ed3\u5e93\u53bb\u627emybatis-spring\u6574\u5408\u7684jar\u5305\uff0c\u9009\u53d6\u5408\u9002\u7684\u7248\u672c\uff08\u6613\u53d1\u751f\u51b2\u7a81\uff09<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u5728spring\u7684applicationContext.xml\u6587\u4ef6\u4e2d\u914d\u7f6edataSource\u548cmybatis\u76f8\u5173\u4fe1\u606f<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<p>&#8211;<\/p>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u5047\u5982\u6240\u6709\u5de5\u4f5c\u90fd\u5230\u4f4d\uff0c\u4e00\u822c\u53ef\u4ee5\u4e00\u6c14\u5475\u6210\uff1b\u4f46\u5f88\u591a\u65f6\u5019\u90fd\u4f1a\u82b1\u4e00\u5806\u65f6\u95f4\u89e3\u51b3jar \u51b2\u7a81\uff0c\u914d\u7f6e\u9879\u7f3a\u5931\uff0c\u5bfc\u81f4\u600e\u4e48\u90fd\u542f\u52a8\u4e0d\u8d77\u6765\u7b49\u7b49\uff0c\u5404\u79cd\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u57282012 \u5e74 10 \u6708\uff0c\u4e00\u4e2a\u53eb Mike Youngstrom \u7684\u4eba\u5728 Spring Jira \u4e2d\u521b\u5efa\u4e86\u4e00\u4e2a\u529f\u80fd\u8bf7\u6c42\uff0c\u8981\u6c42\u5728 Spring Framework \u4e2d\u652f\u6301\u65e0\u5bb9\u5668 Web \u5e94\u7528\u7a0b\u5e8f\u4f53\u7cfb\u7ed3\u6784\uff0c\u63d0\u51fa\u4e86\u5728\u4e3b\u5bb9\u5668\u5f15\u5bfc Spring \u5bb9\u5668\u5185\u914d\u7f6e Web \u5bb9\u5668\u670d\u52a1\uff1b\u8fd9\u4ef6\u4e8b\u60c5\u5bf9 SpringBoot \u7684\u8bde\u751f\u5e94\u8be5\u8bf4\u662f\u8d77\u5230\u4e86\u4e00\u5b9a\u7684\u63a8\u52a8\u4f5c\u7528\u3002<\/p>\n<p>\u6240\u4ee5SpringBoot \u8bbe\u8ba1\u7684\u76ee\u6807\u5c31\u662f\u7b80\u5316\u7e41\u7410\u914d\u7f6e\uff0c\u5feb\u901f\u5efa\u7acbSpring \u5e94\u7528\u3002<\/p>\n<ul>\n<li>\u7136\u540e\u5728\u5f00\u53d1Spring-boot \u5e94\u7528\u7684\u662f\u65f6\u5019\uff0c \u7ecf\u5e38\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u7684pom \u6587\u4ef6\u4e2d\u5f15\u5165\u4e86spring-boot-starter-web\u3001spring-boot-starter-data-redis\u3001mybatis-spring-boot-starter \u8fd9\u6837\u7684\u4f9d\u8d56\uff0c\u7136\u540e\u51e0\u4e4e\u4e0d\u7528\u4efb\u4f55\u914d\u7f6e\u5c31\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u4f9d\u8d56\u7684\u529f\u80fd\uff0c\u771f\u6b63\u7684\u611f\u53d7\u5230\u4e86<strong>\u5f00\u7bb1\u5373\u7528<\/strong>\u7684\u723d\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u4e0b\u9762\u6211\u4eec\u5c31\u5148\u6765\u5c1d\u8bd5\u81ea\u5df1\u5f00\u53d1\u4e00\u4e2aStarter\u3002<\/li>\n<\/ul>\n<h2>2.  \u547d\u540d\u89c4\u8303<\/h2>\n<p>\u5728\u4f7f\u7528spring-boot-starter\uff0c\u4f1a\u53d1\u73b0\uff0c\u6709\u7684\u9879\u76ee\u540d\u79f0\u662f XX-spring-boot-starter\uff0c\u6709\u7684\u662fspring-boot-starter-XX\uff0c\u8fd9\u4e2a\u9879\u76ee\u7684\u540d\u79f0\u6709\u4ec0\u4e48\u8bb2\u7a76\u5462\uff1f\u4ecespringboot\u5b98\u65b9\u6587\u6863\u6458\u5f55:<\/p>\n<p>![]()<\/p>\n<p>\u8fd9\u6bb5\u8bdd\u7684\u5927\u6982\u610f\u601d\u5c31\u662f\uff0c\u9ebb\u70e6\u5927\u5bb6\u9075\u5b88\u8fd9\u4e2a\u547d\u540d\u89c4\u8303\uff1a<\/p>\n<p><strong>Srping\u5b98\u65b9\u547d\u540d\u683c\u5f0f\u4e3a\uff1aspring-boot-starter-{name}<\/strong><\/p>\n<p><strong>\u975eSpring\u5b98\u65b9\u5efa\u8bae\u547d\u540d\u683c\u5f0f\uff1a{name}-spring-boot-starter<\/strong><\/p>\n<h2>3.  \u5f00\u53d1\u793a\u4f8b<\/h2>\n<p>\u4e0b\u9762\u6211\u5c31\u4ee5\u8bb0\u5f55\u65e5\u5fd7\u7684\u4e00\u4e2a\u7ec4\u4ef6\u4e3a\u793a\u4f8b\u6765\u8bb2\u8ff0\u5f00\u53d1\u4e00\u4e2astarter \u7684\u8fc7\u7a0b\u3002<\/p>\n<h3>3.1 \u65b0\u5efa\u5de5\u7a0b<\/h3>\n<p>\u9996\u5148\u65b0\u5efa\u4e00\u4e2amaven \u5de5\u7a0b,\u540d\u79f0\u5b9a\u4e49\u4e3ajd-log-spring-boot-starter<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209784\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h3>3.2 Pom \u5f15\u5165\u4f9d\u8d56<\/h3>\n<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n  xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;\n  &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n  &lt;parent&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n    &lt;version&gt;2.5.13&lt;\/version&gt;\n    &lt;relativePath\/&gt; &lt;!-- lookup parent from repository --&gt;\n  &lt;\/parent&gt;\n  &lt;groupId&gt;com.jd&lt;\/groupId&gt;\n  &lt;artifactId&gt;jd-log-spring-boot-starter&lt;\/artifactId&gt;\n  &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\n  &lt;name&gt;jd-log-spring-boot-starter&lt;\/name&gt;\n  &lt;url&gt;http:\/\/www.example.com&lt;\/url&gt;\n  &lt;properties&gt;\n    &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\n    &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;\n    &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;\n  &lt;\/properties&gt;\n\n\n  &lt;dependencies&gt;\n    &lt;!-- \u63d0\u4f9b\u4e86\u81ea\u52a8\u88c5\u914d\u529f\u80fd--&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-autoconfigure&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;!-- \u5728\u7f16\u8bd1\u65f6\u4f1a\u81ea\u52a8\u6536\u96c6\u914d\u7f6e\u7c7b\u7684\u6761\u4ef6\uff0c\u5199\u5230\u4e00\u4e2aMETA-INF\/spring-autoconfigure-metadata.json\u4e2d--&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-configuration-processor&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;!--\u8bb0\u5f55\u65e5\u5fd7\u4f1a\u7528\u5230\u5207\u9762\uff0c\u6240\u4ee5\u9700\u8981\u5f15\u5165--&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter-aop&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.projectlombok&lt;\/groupId&gt;\n      &lt;artifactId&gt;lombok&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n  &lt;\/dependencies&gt;\n  &lt;build&gt;\n    &lt;plugins&gt;\n      &lt;plugin&gt;\n        &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n        &lt;artifactId&gt;maven-source-plugin&lt;\/artifactId&gt;\n        &lt;version&gt;2.2.1&lt;\/version&gt;\n        &lt;executions&gt;\n          &lt;execution&gt;\n            &lt;id&gt;attach-sources&lt;\/id&gt;\n            &lt;goals&gt;\n              &lt;goal&gt;jar-no-fork&lt;\/goal&gt;\n            &lt;\/goals&gt;\n          &lt;\/execution&gt;\n        &lt;\/executions&gt;\n      &lt;\/plugin&gt;\n    &lt;\/plugins&gt;\n  &lt;\/build&gt;\n&lt;\/project&gt;<\/code><\/pre>\n<p>\u8fd9\u8fb9\u7a0d\u5fae\u89e3\u91ca\u4e00\u4e0b\u8fd9\u51e0\u4e2a\u4f9d\u8d56:<\/p>\n<p>spring-boot-autoconfigure :\u63d0\u4f9b\u81ea\u52a8\u5316\u88c5\u914d\u529f\u80fd\uff0c\u662f\u4e3a\u4e86Spring Boot \u5e94\u7528\u5728\u5404\u4e2a\u6a21\u5757\u63d0\u4f9b\u81ea\u52a8\u5316\u914d\u7f6e\u7684\u4f5c\u7528\uff1b\u5373\u52a0\u5165\u5bf9\u5e94 pom\uff0c\u5c31\u4f1a\u6709\u5bf9\u5e94\u914d\u7f6e\u5176\u4f5c\u7528\uff1b\u6240\u4ee5\u6211\u4eec\u60f3\u8981\u81ea\u52a8\u88c5\u914d\u529f\u80fd\uff0c\u5c31\u9700\u8981\u5f15\u5165\u8fd9\u4e2a\u4f9d\u8d56\u3002<\/p>\n<p>spring-boot-configuration-processor\uff1a\u5c06\u81ea\u5b9a\u4e49\u7684\u914d\u7f6e\u7c7b\u751f\u6210\u914d\u7f6e<a href=\"https:\/\/link.segmentfault.com\/?enc=e2rcTXFo3aQlk528KgS9kg%3D%3D.rX4Gomkdpn2NMhLkYxADVUunsTLnYZCBU%2BsnyrBH%2F9ZZyaYRS%2Bee%2BZsA74qaGjXfxxUiupdCo8WfmvCHX2maFwNRwcFgG5DoriSV1UmFyrQnWmfZduncVcqSuuwTx%2BqK\" rel=\"nofollow\">\u5143\u6570\u636e<\/a>\uff0c\u6240\u4ee5\u5728\u5f15\u7528\u81ea\u5b9a\u4e49STARTER\u7684\u5de5\u7a0b\u7684YML\u6587\u4ef6\u4e2d\uff0c\u7ed9\u81ea\u5b9a\u4e49\u914d\u7f6e\u521d\u59cb\u5316\u65f6\uff0c\u4f1a\u6709\u5c5e\u6027\u540d\u7684\u63d0\u793a\uff1b\u786e\u4fdd\u5728\u4f7f\u7528@ConfigurationProperties\u6ce8\u89e3\u65f6\uff0c\u53ef\u4ee5\u4f18\u96c5\u7684\u8bfb\u53d6\u914d\u7f6e\u4fe1\u606f\uff0c\u5f15\u5165\u8be5\u4f9d\u8d56\u540e\uff0cIDEA\u4e0d\u4f1a\u51fa\u73b0\u201cspring boot configuration annotation processor not configured\u201d\u7684\u9519\u8bef\uff1b\u7f16\u8bd1\u4e4b\u540e\u4f1a\u5728META-INF \u4e0b\u751f\u6210\u4e00\u4e2aspring-configuration-metadata.json \u6587\u4ef6\uff0c\u5927\u6982\u5185\u5bb9\u5c31\u662f\u5b9a\u4e49\u7684\u914d\u7f6e\u7684\u5143\u6570\u636e\uff1b\u6548\u679c\u5982\u4e0b\u622a\u56fe\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209785\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>spring-boot-starter-aop \uff1a\u8fd9\u4e2a\u5c31\u4e0d\u7528\u89e3\u91ca\u4e86\uff0c\u56e0\u4e3a\u793a\u4f8b\u662f\u8bb0\u5f55\u65e5\u5fd7\uff0c\u6211\u4eec\u7528\u5230\u5207\u9762\u7684\u529f\u80fd\uff0c\u6240\u4ee5\u9700\u8981\u5f15\u5165\u3002<\/p>\n<h3>3.3 \u5b9a\u4e49\u5c5e\u6027\u914d\u7f6e<\/h3>\n<pre><code>\/**\n * @author kongxiangdong2\n * @Title: LogProperties\n * @ProjectName jd-log-spring-boot-starter\n * @Description: TODO\n * @date 2022\/9\/110:04\n *\/\n@ConfigurationProperties(prefix = &quot;jd&quot;)\n@Data\npublic class LogProperties {\n\n\n    \/**\n     * \u662f\u5426\u5f00\u542f\u65e5\u5fd7\n     *\/\n    private boolean enable;\n\n\n    \/**\n     * \u5e73\u53f0\uff1a\u4e0d\u540c\u670d\u52a1\u4f7f\u7528\u7684\u533a\u5206\uff0c\u9ed8\u8ba4\u53d6 spring.application.name\n     *\/\n    @Value(&quot;${spring.application.name:#{null}}&quot;)\n    private String platform;<\/code><\/pre>\n<p>@ConfigurationProperties\uff1a\u8be5\u6ce8\u89e3\u548c@Value \u6ce8\u89e3\u4f5c\u7528\u7c7b\u4f3c\uff0c\u7528\u4e8e\u83b7\u53d6\u914d\u7f6e\u6587\u4ef6\u4e2d\u5c5e\u6027\u5b9a\u4e49\u5e76\u7ed1\u5b9a\u5230Java Bean \u6216\u8005\u5c5e\u6027\u4e2d\uff1b\u6362\u53e5\u8bdd\u6765\u8bf4\u5c31\u662f\u5c06\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u5c01\u88c5\u5230JAVA \u5b9e\u4f53\u5bf9\u8c61\uff0c\u65b9\u4fbf\u4f7f\u7528\u548c\u7ba1\u7406\u3002<\/p>\n<p>\u8fd9\u8fb9\u6211\u4eec\u5b9a\u4e49\u4e24\u4e2a\u5c5e\u6027\uff0c\u4e00\u4e2a\u662f\u662f\u5426\u5f00\u542f\u65e5\u5fd7\u7684\u5f00\u5173\uff0c\u4e00\u4e2a\u662f\u6807\u8bc6\u5e73\u53f0\u7684\u540d\u79f0\u3002<\/p>\n<h3>3.4 \u5b9a\u4e49\u81ea\u52a8\u914d\u7f6e\u7c7b<\/h3>\n<pre><code>\/**\n * @author kongxiangdong2\n * @Title: JdLogAutoConfiguration\n * @ProjectName jd-log-spring-boot-starter\n * @Description: TODO\n * @date 2022\/9\/110:06\n *\/\n@Configuration\n@ComponentScan(&quot;com.jd&quot;)\n@ConditionalOnProperty(prefix = &quot;jd&quot;,name = &quot;enable&quot;,havingValue = &quot;true&quot;,matchIfMissing = false)\n@EnableConfigurationProperties({LogProperties.class})\npublic class JdLogAutoConfiguration {\n\n\n   \/\/\n}<\/code><\/pre>\n<p>\u8fd9\u4e2a\u7c7b\u6700\u5173\u952e\u4e86\uff0c\u5b83\u662f\u6574\u4e2astarter \u6700\u91cd\u8981\u7684\u7c7b\uff0c\u5b83\u5c31\u662f\u5c06\u914d\u7f6e\u81ea\u52a8\u88c5\u8f7d\u8fdbspring-boot\u7684\uff1b\u5177\u4f53\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff0c\u4e0b\u9762\u5728\u8bb2\u89e3\u539f\u7406\u7684\u65f6\u5019\u4f1a\u518d\u8be6\u7ec6\u8bf4\u8bf4\uff0c\u8fd9\u91cc\u5148\u5b8c\u6210\u793a\u4f8b\u3002<\/p>\n<p>@Configuration \uff1a\u8fd9\u4e2a\u5c31\u662f\u58f0\u660e\u8fd9\u4e2a\u7c7b\u662f\u4e00\u4e2a\u914d\u7f6e\u7c7b<\/p>\n<p>@ConditionalOnProperty\uff1a\u4f5c\u7528\u662f\u53ef\u4ee5\u6307\u5b9aprefix.name \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5c5e\u6027\u503c\u6765\u5224\u5b9aconfiguration\u662f\u5426\u88ab\u6ce8\u5165\u5230Spring,\u5c31\u62ff\u4e0a\u9762\u4ee3\u7801\u7684\u6765\u8bf4\uff0c\u4f1a\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u4e2d\u662f\u5426\u914d\u7f6ejd.enable \u6765\u5224\u65ad\u662f\u5426\u9700\u8981\u52a0\u8f7dJdLogAutoConfiguration \u7c7b\uff0c\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e0d\u5b58\u5728\u6216\u8005\u914d\u7f6e\u7684\u662f\u7b49\u4e8efalse \u90fd\u4e0d\u4f1a\u8fdb\u884c\u52a0\u8f7d\uff0c\u5982\u679c\u914d\u7f6e\u6210true \u5219\u4f1a\u52a0\u8f7d\uff1b\u6307\u5b9a\u4e86havingValue\uff0c\u8981\u628a\u914d\u7f6e\u9879\u7684\u503c\u4e0ehavingValue\u5bf9\u6bd4\uff0c\u4e00\u81f4\u5219\u52a0\u8f7dBean;\u914d\u7f6e\u6587\u4ef6\u7f3a\u5c11\u914d\u7f6e\uff0c\u4f46\u914d\u7f6e\u4e86matchIfMissing = true\uff0c\u52a0\u8f7dBean\uff0c\u5426\u5219\u4e0d\u52a0\u8f7d\u3002<\/p>\n<p>\u5728\u8fd9\u91cc\u7a0d\u5fae\u6269\u5c55\u4e00\u4e0b\u7ecf\u5e38\u4f7f\u7528\u7684Condition<\/p>\n<table>\n<thead>\n<tr>\n<th>\u6ce8\u89e3<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>@ConditionalOnClass<\/td>\n<td>Class Conditions\u7c7b\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u5f53\u524dclasspath\u4e0b\u6709\u6307\u5b9a\u7c7b\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnMissingClass<\/td>\n<td>Class Conditions\u7c7b\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u5f53\u524dclasspath\u4e0b\u65e0\u6307\u5b9a\u7c7b\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnBean<\/td>\n<td>Bean ConditionsBean\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u5f53\u671f\u5bb9\u5668\u5185\u6709\u6307\u5b9abean\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnMissingBean<\/td>\n<td>Bean ConditionsBean\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u5f53\u671f\u5bb9\u5668\u5185\u65e0\u6307\u5b9abean\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnProperty<\/td>\n<td>Property Conditions\u73af\u5883\u53d8\u91cf\u6761\u4ef6\u6ce8\u89e3\uff08\u542b\u914d\u7f6e\u6587\u4ef6\uff09<\/td>\n<td>prefix \u524d\u7f00name \u540d\u79f0havingValue \u7528\u4e8e\u5339\u914d\u914d\u7f6e\u9879\u503cmatchIfMissing \u6ca1\u627e\u6307\u5b9a\u914d\u7f6e\u9879\u65f6\u7684\u9ed8\u8ba4\u503c<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnResource<\/td>\n<td>ResourceConditions \u8d44\u6e90\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u6709\u6307\u5b9a\u8d44\u6e90\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnWebApplication<\/td>\n<td>Web Application Conditionsweb\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u662fweb\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnNotWebApplication<\/td>\n<td>Web Application Conditionsweb\u6761\u4ef6\u6ce8\u89e3<\/td>\n<td>\u4e0d\u662fweb\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>@ConditionalOnExpression<\/td>\n<td>SpEL Expression Conditions<\/td>\n<td>\u7b26\u5408SpEL \u8868\u8fbe\u5f0f\u624d\u52a0\u8f7d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>@EnableConfigurationProperties\u4f7f@ConfigurationProperties \u6ce8\u89e3\u7684\u7c7b\u751f\u6548\u3002<\/p>\n<h3>3.5 \u914d\u7f6eEnableAutoConfiguration<\/h3>\n<p>\u5728resources\/META-INF\/ \u76ee\u5f55\u65b0\u5efaspring.factories \u6587\u4ef6\uff0c\u914d\u7f6e\u5185\u5bb9\u5982\u4e0b\uff1b<\/p>\n<pre><code>org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.jd.JdLogAutoConfiguration<\/code><\/pre>\n<p>\u597d\u4e86\uff0c\u81f3\u6b64\u81ea\u5b9a\u4e49Starter \u5927\u4f53\u6846\u67b6\u5df2\u7ecf\u597d\u4e86\uff0c\u4e0b\u9762\u5c31\u662f\u6211\u4eec\u8bb0\u5f55\u65e5\u5fd7\u7684\u529f\u80fd\u3002<\/p>\n<h3>3.6 \u4e1a\u52a1\u529f\u80fd\u5b9e\u73b0<\/h3>\n<p>\u9996\u5148\u6211\u4eec\u5148\u5b9a\u4e49\u4e00\u4e2a\u6ce8\u89e3Jdlog<\/p>\n<pre><code>\/**\n * @author kongxiangdong2\n * @Title: Jdlog\n * @ProjectName jd-log-spring-boot-starter\n * @Description: TODO\n * @date 2022\/9\/110:04\n *\/\n@Target(ElementType.METHOD)\n@Retention(RetentionPolicy.RUNTIME)\npublic @interface Jdlog {\n}<\/code><\/pre>\n<p>\u5b9a\u4e49\u5207\u9762\u6267\u884c\u903b\u8f91\uff0c\u8fd9\u8fb9\u5c31\u7b80\u5355\u7684\u6253\u5370\u4e00\u4e0b\u914d\u7f6e\u6587\u4ef6\u7684\u5c5e\u6027\u503c+\u76ee\u6807\u6267\u884c\u65b9\u6cd5+\u8017\u65f6\u3002<\/p>\n<pre><code>import com.jd.annotation.Jdlog;\nimport com.jd.config.LogProperties;\nimport lombok.AllArgsConstructor;\nimport lombok.extern.slf4j.Slf4j;\nimport org.aspectj.lang.ProceedingJoinPoint;\nimport org.aspectj.lang.annotation.Around;\nimport org.aspectj.lang.annotation.Aspect;\nimport org.aspectj.lang.annotation.Pointcut;\nimport org.springframework.stereotype.Component;\n\n\n\/**\n * @author kongxiangdong2\n * @Title: LogAspectjProcess\n * @ProjectName jd-log-spring-boot-starter\n * @Description: TODO\n * @date 2022\/9\/111:12\n *\/\n@Aspect\n@Component\n@Slf4j\n@AllArgsConstructor\npublic class LogAspectjProcess {\n\n\n    LogProperties logProperties;\n\n\n    \/**\n     * \u5b9a\u4e49\u5207\u70b9\n     *\/\n    @Pointcut(&quot;@annotation(com.jd.annotation.Jdlog)&quot;)\n    public void pointCut(){}\n\n\n    \/**\n     * \u73af\u7ed5\u901a\u77e5\n     *\n     * @param thisJoinPoint\n     * @param jdlog\n     * @return\n     *\/\n    @Around(&quot;pointCut() &amp;&amp; @annotation(jdlog)&quot;)\n    public Object around(ProceedingJoinPoint thisJoinPoint, Jdlog jdlog){\n\n\n        \/\/\u6267\u884c\u65b9\u6cd5\u540d\u79f0\n        String taskName = thisJoinPoint.getSignature()\n                .toString().substring(\n                        thisJoinPoint.getSignature()\n                                .toString().indexOf(&quot; &quot;),\n                        thisJoinPoint.getSignature().toString().indexOf(&quot;(&quot;));\n        taskName = taskName.trim();\n        long time = System.currentTimeMillis();\n        Object result = null;\n        try {\n            result = thisJoinPoint.proceed();\n        } catch (Throwable throwable) {\n            throwable.printStackTrace();\n        }\n        log.info(&quot;{} -- method:{} run :{} ms&quot;,logProperties.getPlatform(), taskName,\n                (System.currentTimeMillis() - time));\n        return result;\n\n\n    <\/code><\/pre>\n<p>\u6574\u4f53\u9879\u76ee\u7ed3\u6784\u5c31\u662f\u8fd9\u6837\u5b50<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209786\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u597d\u4e86\uff0c\u73b0\u5728\u5c31\u53ef\u4ee5\u6253\u5305\u7f16\u8bd1\u5b89\u88c5<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209787\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h3>3.7 \u6d4b\u8bd5\u4f7f\u7528<\/h3>\n<p>\u7136\u540e\u5c31\u53ef\u4ee5\u5728\u5176\u4ed6\u9879\u76ee\u4e2d\u5f15\u5165\u4f7f\u7528\u4e86\uff1b\u4e0b\u9762\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684spring-boot web \u9879\u76ee\u505a\u4e2a\u6d4b\u8bd5\uff0c\u5728pom \u4e2d\u5f15\u5165\u4e0b\u9762\u7684\u4f9d\u8d56\u914d\u7f6e\u3002<\/p>\n<pre><code>  &lt;dependency&gt;\n      &lt;groupId&gt;com.jd&lt;\/groupId&gt;\n      &lt;artifactId&gt;jd-log-spring-boot-starter&lt;\/artifactId&gt;\n      &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\n    &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u589e\u52a0\u4e00\u4e2ahttp \u8bbf\u95ee\u7684\u65b9\u6cd5\uff0c\u6807\u6ce8\u4e0a@Jdlog \u6ce8\u89e3<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209788\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>application.yaml \u6587\u4ef6\u4e2d\u914d\u7f6e<\/p>\n<pre><code>jd:\n  enable: true\n  platform: &quot;\u6d4b\u8bd5\u9879\u76ee&quot;<\/code><\/pre>\n<p>\u542f\u52a8\u6d4b\u8bd5\uff0c\u8bbf\u95ee\u5730\u5740<a href=\"https:\/\/link.segmentfault.com\/?enc=B5iXWKejo6Vhda8t3Ca8ag%3D%3D.O32dv31XUD3jSDExhxvEu76dh1Lo0US38rn54By8UTr02IX34xIYQIKv40hAvDRW\" rel=\"nofollow\">http:\/\/localhost:8080\/test\/me&#8230;<\/a>\uff0c\u63a7\u5236\u53f0\u6253\u5370\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209789\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u548b\u6837\uff0c\u81ea\u5b9a\u4e49\u7684Starter\u662f\u4e0d\u662f\u7279\u522b\u7684\u7b80\u5355\u554a\uff0c\u5feb\u52a8\u624b\u8bd5\u8bd5\u5427\uff01<\/p>\n<p>\u4e0a\u9762\u6211\u4eec\u8bb2\u7684\u90fd\u662f\u600e\u4e48\u53bb\u5f00\u53d1\u4e00\u4e2astarter,\u4f46\u662f\u5230\u5e95\u4e3a\u4ec0\u4e48\u8981\u8fd9\u6837\uff0cspring-boot \u662f\u5982\u4f55\u53bb\u5b9e\u73b0\u7684\uff1f\u662f\u4e0d\u662f\u8fd8\u4e0d\u77e5\u9053\uff1f\u90a3\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u8bf4\u8bf4\uff1b<\/p>\n<p>\u4ee3\u7801\u793a\u4f8b\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=pv5Mj2%2FKOHed6qiN26bltw%3D%3D.mWO2EIgBYzyQKKo9bDZlvB1fJ7wO%2FBhVVPNgI667AyfeZEQ4cNdNtAWM%2FECajWV%2Fq3GseuYmBoBDihTPeDgo0DoujQIIo1e16DE9m6HJGzg%3D\" rel=\"nofollow\">https:\/\/coding.jd.com\/kongxia&#8230;<\/a><\/p>\n<h2>4. \u539f\u7406\u8bb2\u89e3<\/h2>\n<p>\u6211\u4eec\u4e0a\u9762\u5df2\u7ecf\u770b\u5230\u4e00\u4e2astarter,\u53ea\u9700\u8981\u5f15\u5165\u5230pom \u6587\u4ef6\u4e2d\uff0c\u518d\u914d\u7f6e\u4e00\u4e0b(\u5176\u5b9e\u90fd\u53ef\u4ee5\u4e0d\u914d\u7f6e)jd.enable=true\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8bb0\u5f55\u65e5\u5fd7\u7684\u529f\u80fd\u4e86\uff0cSpring-boot \u662f\u600e\u4e48\u505a\u5230\u7684\uff1f<\/p>\n<p>\u5728\u5f00\u59cb\u7684\u65f6\u5019\u8bf4\u8fc7\uff0cSpring-boot \u7684\u597d\u5904\u5c31\u662f\u53ef\u4ee5\u81ea\u52a8\u88c5\u914d\u3002\u90a3\u4e0b\u9762\u6211\u5c31\u6765\u8bf4\u8bf4\u81ea\u52a8\u88c5\u914d\u7684\u539f\u7406\u3002<\/p>\n<p>\u76f8\u6bd4\u4e8e\u4f20\u7edfSpring \u5e94\u7528\uff0c\u6211\u4eec\u642d\u5efa\u4e00\u4e2aSpringBoot \u5e94\u7528\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5f15\u5165\u4e00\u4e2a\u6ce8\u89e3\uff08\u524d\u63d0\uff1a\u5f15\u5165springBoot y\u4f9d\u8d56\uff09@SpringBootApplication\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\uff1b\u6240\u4ee5\u6211\u4eec\u5c31\u4ece\u8fd9\u4e2a\u6ce8\u89e3\u5f00\u59cb\u5165\u624b\uff0c\u770b\u770b\u8fd9\u4e2a\u6ce8\u89e3\u5230\u5e95\u505a\u4e86\u5199\u4ec0\u4e48\uff1f<\/p>\n<h3>SpringBootApplication \u6ce8\u89e3<\/h3>\n<p>\u70b9\u5f00@SpringBootApplication\u6ce8\u89e3\u53ef\u4ee5\u770b\u5230\u5305\u542b\u4e86@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan\u4e09\u4e2a\u6ce8\u89e3\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209790\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u524d\u9762\u7684\u56db\u4e2a\u6ce8\u89e3\u5c31\u4e0d\u7528\u8fc7\u591a\u53d9\u8ff0\u4e86\uff0c\u662f\u5b9a\u4e49\u6ce8\u89e3\u6700\u57fa\u672c\u7684\uff0c\u5173\u952e\u5728\u4e8e\u540e\u9762\u7684\u4e09\u4e2a\u6ce8\u89e3:@SpringBootConfiguration\uff0c@EnableAutoConfiguration\uff0c@ComponentScan,\u5176\u5b9e\u4e5f\u5c31\u662f\u8bf4\u5728\u542f\u52a8\u7c7b\u4e0a\u5982\u679c\u4e0d\u4f7f\u7528@SpringBootApplication \u8fd9\u4e2a\u590d\u5408\u6ce8\u89e3\uff0c\u76f4\u63a5\u4f7f\u7528\u8005\u4e09\u4e2a\u6ce8\u89e3\u4e00\u6837\u53ef\u4ee5\u8fbe\u5230\u76f8\u540c\u7684\u6548\u679c\u3002<\/p>\n<p>@SpringBootConfiguration \u6ce8\u89e3\uff1a\u6211\u4eec\u518d\u6b21\u70b9\u8fdb\u53bb\u770b\u8fd9\u4e2a\u6ce8\u89e3\uff0c\u5176\u5b9e\u5b83\u5c31\u662f\u4e00\u4e2a@Configuration \u6ce8\u89e3\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209791\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h4>@ComponentScan \u6ce8\u89e3<\/h4>\n<p>@ComponentScan \u6ce8\u89e3\uff1a\u914d\u7f6e\u5305\u626b\u63cf\u5b9a\u4e49\u7684\u626b\u63cf\u8def\u5f84\uff0c\u628a\u7b26\u5408\u626b\u63cf\u89c4\u5219\u7684\u7c7b\u88c5\u914d\u5230spring\u5bb9\u5668<\/p>\n<h4>@EnableAutoConfiguration \u6ce8\u89e3<\/h4>\n<p>@EnableAutoConfiguration \u6253\u5f00\u81ea\u52a8\u88c5\u914d(\u81ea\u52a8\u914d\u7f6e\u7740\u91cd\u6765\u770b\u8be5\u6ce8\u89e3)<\/p>\n<table>\n<thead>\n<tr>\n<th>\u6ce8\u89e3<\/th>\n<th>\u4f5c\u7528<\/th>\n<th>\u89e3\u91ca<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>@SpringBootConfiguration<\/td>\n<td>\u6807\u8bb0\u5f53\u524d\u7c7b\u4e3a\u914d\u7f6e\u7c7b<\/td>\n<td>\u52a0\u4e0a\u8fd9\u4e2a\u6ce8\u89e3\u5c31\u662f\u4e3a\u4e86\u8ba9\u5f53\u524d\u7c7b\u4f5c\u4e3a\u4e00\u4e2a\u914d\u7f6e\u7c7b\u4ea4\u7531 Spring \u7684 IOC \u5bb9\u5668\u8fdb\u884c\u7ba1\u7406\uff0c\u56e0\u4e3a\u524d\u9762\u6211\u4eec\u8bf4\u4e86\uff0cSpringBoot \u672c\u8d28\u4e0a\u8fd8\u662f Spring\uff0c\u6240\u4ee5\u539f\u5c5e\u4e8e Spring \u7684\u6ce8\u89e3 @Configuration \u5728 SpringBoot \u4e2d\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5e94\u7528<\/td>\n<\/tr>\n<tr>\n<td>@ComponentScan<\/td>\n<td>\u914d\u7f6e\u5305\u626b\u63cf\u5b9a\u4e49\u7684\u626b\u63cf\u8def\u5f84\uff0c\u628a\u7b26\u5408\u626b\u63cf\u89c4\u5219\u7684\u7c7b\u88c5\u914d\u5230spring\u5bb9\u5668<\/td>\n<td>\u7528\u4e8e\u5b9a\u4e49 Spring \u7684\u626b\u63cf\u8def\u5f84\uff0c\u7b49\u4ef7\u4e8e\u5728 xml \u6587\u4ef6\u4e2d\u914d\u7f6e &lt;context:component-scan&gt;\uff0c\u5047\u5982\u4e0d\u914d\u7f6e\u626b\u63cf\u8def\u5f84\uff0c\u90a3\u4e48 Spring \u5c31\u4f1a\u9ed8\u8ba4\u626b\u63cf\u5f53\u524d\u7c7b\u6240\u5728\u7684\u5305\u53ca\u5176\u5b50\u5305\u4e2d\u7684\u6240\u6709\u6807\u6ce8\u4e86 @Component\uff0c@Service\uff0c@Controller \u7b49\u6ce8\u89e3\u7684\u7c7b\u3002<\/td>\n<\/tr>\n<tr>\n<td>@EnableAutoConfiguration<\/td>\n<td>\u6253\u5f00\u81ea\u52a8\u88c5\u914d<\/td>\n<td>\u4e0b\u9762\u7740\u91cd\u8bb2\u89e3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u518d\u6b21\u70b9\u51fb@EnableAutoConfiguration\u8fdb\u5165\u67e5\u770b\uff0c\u5b83\u662f\u4e00\u4e2a\u7531 @AutoConfigurationPackage \u548c @Import \u6ce8\u89e3\u7ec4\u6210\u7684\u590d\u5408\u6ce8\u89e3\uff1b<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209792\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u9996\u5148\u6211\u4eec\u5148\u6765\u770b@Import \u8fd9\u4e2a\u6ce8\u89e3\uff0c\u8fd9\u4e2a\u662f\u6bd4\u8f83\u5173\u952e\u7684\u4e00\u4e2a\u6ce8\u89e3\uff1b<\/p>\n<p>\u5728\u8bf4\u8fd9\u4e2a\u6ce8\u89e3\u4e4b\u524d\u6211\u4eec\u5148\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u5982\u6211\u4eec\u6709\u4e00\u4e2a\u7c7bDemo,\u5b83\u662f\u4e00\u4e2a\u4e0d\u5728\u542f\u52a8\u914d\u7f6e\u7c7b\u76ee\u5f55\u4e4b\u4e0b\u7684\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u5b83\u4e0d\u4f1a\u88ab\u626b\u63cf\u5230\uff0cSpring \u4e5f\u65e0\u6cd5\u611f\u77e5\u5230\u5b83\u7684\u5b58\u5728\uff0c\u90a3\u4e48\u5982\u679c\u9700\u8981\u80fd\u5c06\u5b83\u88ab\u626b\u63cf\u5230\uff0c\u662f\u4e0d\u662f\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u52a0@Import \u6ce8\u89e3\u6765\u5bfc\u5165Demo \u7c7b\uff0c\u7c7b\u4f3c\u5982\u4e0b\u4ee3\u7801<\/p>\n<pre><code>@Configuration\n@Import(Demo.class)\npublic class MyConfiguration {\n}<\/code><\/pre>\n<p>\u6240\u4ee5\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053@Import \u6ce8\u89e3\u5176\u5b9e\u5c31\u662f\u4e3a\u4e86\u53bb\u5bfc\u5165\u4e00\u4e2a\u7c7b\u3002\u6240\u4ee5\u8fd9\u91cc@Import({AutoConfigurationImportSelector.class}) \u5c31\u662f\u4e3a\u4e86\u5bfc\u5165AutoConfigurationImportSelector \u7c7b\uff0c\u90a3\u6211\u4eec\u7ee7\u7eed\u6765\u770b\u8fd9\u4e2a\u7c7b\uff0cAutoConfigurationImportSelector\u5b9e\u73b0\u7684\u662f<code>DeferredImportSelector<\/code>\u63a5\u53e3\uff0c\u8fd9\u662f\u4e00\u4e2a\u5ef6\u8fdf\u5bfc\u5165\u7684\u7c7b\uff1b\u518d\u7ec6\u770b\u4f1a\u6709\u4e00\u4e2a\u65b9\u6cd5\u6bd4\u8f83\u663e\u773c\uff0c\u6839\u636e\u6ce8\u89e3\u5143\u6570\u636e\u6765\u9009\u62e9\u5bfc\u5165\u7ec4\u4ef6\uff0c\u5f53\u6ce8\u89e3\u5143\u6570\u636e\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\uff1b\u5426\u5219\u5c31\u8c03\u7528getAutoConfigurationEntry\u00a0\uff0c\u65b9\u6cd5\u4e2d\u4f1a\u4f7f\u7528AutoConfigurationEntry\u7684getConfigurations(),configurations\u662f\u4e00\u4e2a<code>List&lt;String&gt;<\/code>,\u90a3\u4e48\u6211\u4eec\u770b\u4e0bAutoConfigurationEntry\u662f\u600e\u4e48\u751f\u6210\u7684\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209793\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u8fdb\u5165\u5230getAutoConfigurationEntry \u65b9\u6cd5\u4e2d\u53ef\u4ee5\u770b\u5230\u4e3b\u8981\u662fgetCandidateConfigurations \u6765\u83b7\u53d6\u5019\u9009\u7684 Bean\uff0c\u5e76\u5c06\u5176\u5b58\u4e3a\u4e00\u4e2a\u96c6\u5408\uff1b\u540e\u7eed\u7684\u65b9\u6cd5\u90fd\u662f\u5728\u53bb\u91cd\uff0c\u6821\u9a8c\u7b49\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209794\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u6211\u4eec\u7ee7\u7eed\u5f80getCandidateConfigurations \u65b9\u6cd5\u91cc\u770b\uff0c\u6700\u7ec8\u901a\u8fc7SpringFactoriesLoader.loadFactoryNames\u6765\u83b7\u53d6\u6700\u7ec8\u7684configurations\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u65ad\u8a00\u53d1\u73b0\u4f1a\u4f7f\u7528\u5230META-INF\/spring.factories\u6587\u4ef6\uff0c\u90a3\u4e48\u6211\u4eec\u518d\u8fdb\u5165SpringFactoriesLoader.loadFactoryNames()\u4e2d\u6765\u770b\u4e0b\u6700\u7ec8\u7684\u5b9e\u73b0\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209795\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>SpringFactoriesLoader.loadFactoryNames()\u65b9\u6cd5\u4f1a\u8bfb\u53d6META-INF\/spring.factories\u6587\u4ef6\u4e0b\u7684\u5185\u5bb9\u5230Map\u4e2d\uff0c\u518d\u7ed3\u5408\u4f20\u5165\u7684factoryType=EnableAutoConfiguration.class,\u56e0\u6b64\u4f1a\u62ff\u5230 org.springframework.boot.autoconfigure.EnableAutoConfiguration\u4e3akey\u5bf9\u5e94\u7684\u5404\u4e2aXXAutoConfiguration\u7684\u503c\uff0c\u7136\u540espringboot\u5728\u7ed3\u5408\u5404\u4e2astarter\u4e2d\u7684\u4ee3\u7801\u5b8c\u6210\u5bf9\u4e8eXXAutoConfiguration\u4e2d\u7684Bean\u7684\u52a0\u8f7d\u52a8\u4f5c\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209796\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209797\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u8fb9\u518d\u6269\u5c55\u4e00\u4e0b\u8fd9\u4e2a\u5185\u5bb9\uff0c\u901a\u8fc7 SpringFactoriesLoader \u6765\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6 spring.factories \u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u7684\u8fd9\u79cd\u65b9\u5f0f\u662f\u4e00\u79cd SPI \u7684\u601d\u60f3\u3002<\/p>\n<h4>@AutoConfigurationPackage \u6ce8\u89e3<\/h4>\n<p>\u8fdb\u5165\u8fd9\u4e2a\u6ce8\u89e3\u770b\uff0c\u5176\u5b9e\u5b83\u5c31\u662f\u5bfc\u5165\u4e86Registrar \u8fd9\u4e2a\u7c7b<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209798\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u518d\u8fdb\u5165\u8fd9\u4e2a\u7c7b\u67e5\u770b\uff0c\u5b83\u5176\u5b9e\u662f\u4e00\u4e2a\u5185\u90e8\u7c7b\uff0c\u770b\u4ee3\u7801\u7684\u5927\u6982\u610f\u601d\u5c31\u662f\u8bfb\u53d6\u5230\u6211\u4eec\u5728\u6700\u5916\u5c42\u7684 @SpringBootApplication \u6ce8\u89e3\u4e2d\u914d\u7f6e\u7684\u626b\u63cf\u8def\u5f84\uff08\u6ca1\u6709\u914d\u7f6e\u5219\u9ed8\u8ba4\u5f53\u524d\u5305\u4e0b\uff09\uff0c\u7136\u540e\u628a\u626b\u63cf\u8def\u5f84\u4e0b\u9762\u7684Bean\u6ce8\u518c\u5230\u5bb9\u5668\u4e2d\uff1b<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043209799\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u597d\u4e86\uff0c\u73b0\u5728\u6211\u4eec\u5927\u6982\u6765\u7406\u4e00\u4e0b\u6574\u4e2a\u81ea\u52a8\u88c5\u914d\u7684\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li>\u542f\u52a8\u7c7b\u4e2d\u901a\u8fc7\u4f7f\u7528@SpringBootApplication\u5b9e\u73b0\u81ea\u52a8\u88c5\u914d\u7684\u529f\u80fd\uff1b<\/li>\n<\/ol>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ol>\n<li>\u5b9e\u9645\u6ce8\u89e3@SpringBootApplication\u662f\u501f\u52a9\u6ce8\u89e3@EnableAutoConfiguration\u7684\u529f\u80fd\u3002<\/li>\n<\/ol>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ol>\n<li>\u5728\u6ce8\u89e3@EnableAutoConfiguration\u4e2d\u53c8\u6709\u4e24\u4e2a\u6ce8\u89e3\uff0c@AutoConfigurationPackage\uff0c@EnableAutoConfiguration\u3002<\/li>\n<\/ol>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ol>\n<li>\u901a\u8fc7@AutoConfigurationPackage\u5b9e\u73b0\u5bf9\u4e8e\u5f53\u524d\u9879\u76ee\u4e2dBean\u7684\u8fdb\u884c\u52a0\u8f7d\uff1b<\/li>\n<\/ol>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ol>\n<li>@EnableAutoConfiguration\u901a\u8fc7@Import({AutoConfigurationImportSelector.class})\u5b9e\u73b0\u5bf9\u4e8ePom\u5f15\u5165\u7684start\u4e2d\u7684XXAutoConfiguration\u7684\u52a0\u8f7d\uff1b<\/li>\n<\/ol>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ol>\n<li>@AutoConfigurationImportSelector\u7c7b\u4e2d\u901a\u8fc7SpringFactoriesLoader\u8bfb\u53d6 META-INF\/spring.factories\u4e2dkey\u4e3aorg.springframework.boot.autoconfigure.EnableAutoConfiguration\u5bf9\u5e94\u7684\u5404\u4e2aXXAutoConfiguration\u7684\u503c\uff0c\u7136\u540espringboot\u5728\u7ed3\u5408\u5404\u4e2astart\u4e2d\u7684\u4ee3\u7801\u5b8c\u6210\u5bf9\u4e8eXXAutoConfiguration\u4e2d\u7684Bean\u7684\u52a0\u8f7d\u52a8\u4f5c\uff1b<\/li>\n<\/ol>\n<p>\u5230\u8fd9\u91cc\u662f\u4e0d\u662f\u5df2\u7ecf\u53ef\u4ee5\u5f88\u4e86\u7136\u5bf9\u6211\u4eec\u4e4b\u524d\u5f00\u53d1starter\u4e2d\u7684\u5b9a\u4e49\u4e86\u554a\uff0c\u8d76\u7d27\u8bd5\u8bd5\u5427<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043209782\">https:\/\/segmentfault.com\/a\/1190000043209782<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eac\u4e1c\u7269\u6d41 \u5b54\u7965\u4e1c _____ _ ____ _ \/ ____| (_) | _ \/ | | | (___ _  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10007037","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10007037"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007037\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10007037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10007037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10007037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}