{"id":10856,"date":"2023-04-21T15:40:28","date_gmt":"2023-04-21T07:40:28","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10856"},"modified":"2023-04-21T15:42:53","modified_gmt":"2023-04-21T07:42:53","slug":"springboot%ef%bc%9a%e8%ae%a4%e8%ae%a4%e7%9c%9f%e7%9c%9f%e6%a2%b3%e7%90%86%e4%b8%80%e9%81%8d%e8%87%aa%e5%8a%a8%e8%a3%85%e9%85%8d%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10856","title":{"rendered":"SpringBoot\uff1a\u8ba4\u8ba4\u771f\u771f\u68b3\u7406\u4e00\u904d\u81ea\u52a8\u88c5\u914d\u539f\u7406"},"content":{"rendered":"\n<p><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Spring\u7ffb\u8bd1\u4e3a\u4e2d\u6587\u662f\u201c\u6625\u5929\u201d\uff0c\u7684\u786e\uff0c\u5728\u67d0\u6bb5\u65f6\u95f4\u5185\uff0c\u5b83\u7ed9Java\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u8fc7\u6625\u5929\uff0c\u4f46\u662f\u968f\u7740\u6211\u4eec\u9879\u76ee\u89c4\u6a21\u7684\u6269\u5927\uff0cSpring\u9700\u8981\u914d\u7f6e\u7684\u5730\u65b9\u5c31\u8d8a\u6765\u8d8a\u591a\uff0c\u5938\u5f20\u70b9\u8bf4\uff0c\u201c\u914d\u7f6e\u4e24\u5c0f\u65f6\uff0cCoding\u4e94\u5206\u949f\u201d\u3002\u8fd9\u79cd\u7eb7\u7e41\u590d\u6742\u7684xml\u914d\u7f6e\u968f\u7740\u8f6f\u4ef6\u884c\u4e1a\u4e00\u6b65\u6b65\u5730\u53d1\u5c55\uff0c\u5fc5\u5c06\u9010\u6b65\u9000\u51fa\u5386\u53f2\u821e\u53f0\u3002<\/p>\n\n\n\n<p><strong>SpringBoot\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Spring Boot\u662f\u7531Pivotal\u56e2\u961f\u63d0\u4f9b\u7684\u5168\u65b0\u6846\u67b6\uff0c\u5176\u8bbe\u8ba1\u76ee\u7684\u662f\u7528\u6765\u7b80\u5316\u65b0Spring\u5e94\u7528\u7684\u521d\u59cb\u642d\u5efa\u4ee5\u53ca\u5f00\u53d1\u8fc7\u7a0b\u3002\u8be5\u6846\u67b6\u4f7f\u7528\u4e86\u7279\u5b9a\u7684\u65b9\u5f0f\u6765\u8fdb\u884c\u914d\u7f6e\uff0c\u4ece\u800c\u4f7f\u5f00\u53d1\u4eba\u5458\u4e0d\u518d\u9700\u8981\u5b9a\u4e49\u6837\u677f\u5316\u7684\u914d\u7f6e\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cSpring Boot\u81f4\u529b\u4e8e\u5728\u84ec\u52c3\u53d1\u5c55\u7684\u5feb\u901f\u5e94\u7528\u5f00\u53d1\u9886\u57df(rapid application development)\u6210\u4e3a\u9886\u5bfc\u8005\u3002<\/p>\n\n\n\n<p><strong>SpringBoot\u6240\u5177\u5907\u7684\u7279\u5f81\u6709\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u53ef\u4ee5\u521b\u5efa\u72ec\u7acb\u7684Spring\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u57fa\u4e8e\u5176Maven\u6216Gradle\u63d2\u4ef6\uff0c\u53ef\u4ee5\u521b\u5efa\u53ef\u6267\u884c\u7684JARs\u548cWARs\uff1b<\/li><li>\u5185\u5d4cTomcat\u6216Jetty\u7b49Servlet\u5bb9\u5668\uff1b<\/li><li>\u63d0\u4f9b\u81ea\u52a8\u914d\u7f6e\u7684\u201cstarter\u201d\u9879\u76ee\u5bf9\u8c61\u6a21\u578b\uff08POMS\uff09\u4ee5\u7b80\u5316Maven\u914d\u7f6e\uff1b<\/li><li>\u5c3d\u53ef\u80fd\u81ea\u52a8\u914d\u7f6eSpring\u5bb9\u5668\uff1b<\/li><li>\u63d0\u4f9b\u51c6\u5907\u597d\u7684\u7279\u6027\uff0c\u5982\u6307\u6807\u3001\u5065\u5eb7\u68c0\u67e5\u548c\u5916\u90e8\u5316\u914d\u7f6e\uff1b<\/li><li>\u7edd\u5bf9\u6ca1\u6709\u4ee3\u7801\u751f\u6210\uff0c\u4e0d\u9700\u8981XML\u914d\u7f6e\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u81ea\u5df1\u7684\u7406\u89e3\uff1a<\/strong><\/p>\n\n\n\n<p>SpringBoot\uff0c\u987e\u540d\u601d\u4e49\uff0c\u7ed9\u4eba\u7684\u611f\u89c9\u5c31\u662f\u8ba9Spring\u542f\u52a8\u7684\u8fd9\u4e48\u4e00\u4e2a\u9879\u76ee\u3002\u5728\u8fc7\u53bb\uff0c\u6211\u4eec\u8981\u8ba9\u4e00\u4e2aSpring\u9879\u76ee\u542f\u52a8\uff0c\u5f80\u5f80\u9700\u8981\u914d\u7f6e\u5f88\u591a\u7684xml\u914d\u7f6e\u6587\u4ef6\uff0c\u4f46\u662f\u5728\u4f7f\u7528SpringBoot\u4e4b\u540e\uff0c\u6211\u4eec\u751a\u81f3\u65e0\u9700\u5199\u4e00\u884cxml\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u6574\u4e2a\u9879\u76ee\u542f\u52a8\uff0c\u8fd9\u79cd\u201c\u96f6\u914d\u7f6e\u201d\u7684\u505a\u6cd5\u51cf\u8f7b\u4e86\u5f00\u53d1\u4eba\u5458\u5f88\u591a\u7684\u5de5\u4f5c\u91cf\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u4eba\u5458\u4e00\u5fc3\u6251\u5728\u4e1a\u52a1\u903b\u8f91\u7684\u8bbe\u8ba1\u4e0a\uff0c\u4f7f\u9879\u76ee\u7684\u903b\u8f91\u66f4\u52a0\u5b8c\u5584\u3002<\/p>\n\n\n\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u5176\u91c7\u7528\u4e86JavaConfig\u7684\u914d\u7f6e\u98ce\u683c\uff0c\u5bfc\u5165\u7ec4\u4ef6\u7684\u65b9\u5f0f\u4e5f\u7531\u539f\u6765\u7684\u76f4\u63a5\u914d\u7f6e\u6539\u4e3a@EnableXXXX\uff0c\u8fd9\u79cd\u7eafJava\u4ee3\u7801\u7684\u914d\u7f6e\u548c\u5bfc\u5165\u7ec4\u4ef6\u7684\u65b9\u5f0f\uff0c\u4f7f\u4ee3\u7801\u770b\u4e0a\u53bb\u66f4\u52a0\u7684\u4f18\u96c5\uff0c\u6240\u4ee5SpringBoot\u5982\u4eca\u53d7\u5230\u5927\u5c0f\u516c\u53f8\u548c\u5927\u591a\u6570\u7a0b\u5e8f\u5458\u7684\u9752\u7750\uff0c\u4e0d\u662f\u6ca1\u6709\u539f\u56e0\u7684\u3002<\/p>\n\n\n\n<p>SpringBoot\u4e4b\u6240\u4ee5\u53ef\u4ee5\u505a\u5230\u7b80\u5316\u914d\u7f6e\u6587\u4ef6\u76f4\u63a5\u542f\u52a8\uff0c\u65e0\u5916\u4e4e\u662f\u5176\u5185\u90e8\u7684\u4e24\u79cd\u8bbe\u8ba1\u7b56\u7565\uff1a<strong>\u5f00\u7bb1\u5373\u7528\u548c\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e<\/strong>\u3002<\/p>\n\n\n\n<p>\u5f00\u7bb1\u5373\u7528\uff1a<strong>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u901a\u8fc7maven\u9879\u76ee\u7684pom\u6587\u4ef6\u4e2d\u6dfb\u52a0\u76f8\u5173\u4f9d\u8d56\u5305\uff0c\u7136\u540e\u901a\u8fc7\u76f8\u5e94\u7684\u6ce8\u89e3\u6765\u4ee3\u66ff\u7e41\u7410\u7684XML\u914d\u7f6e\u4ee5\u7ba1\u7406\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u3002<\/strong><\/p>\n\n\n\n<p>\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\uff1a<strong>\u7531SpringBoot\u672c\u8eab\u6765\u914d\u7f6e\u76ee\u6807\u7ed3\u6784\uff0c\u7531\u5f00\u53d1\u8005\u5728\u7ed3\u6784\u4e2d\u6dfb\u52a0\u4fe1\u606f\u7684\u8f6f\u4ef6\u8bbe\u8ba1\u8303\u5f0f\u3002\u8fd9\u4e00\u7279\u70b9\u867d\u964d\u4f4e\u4e86\u90e8\u5206\u7075\u6d3b\u6027\uff0c\u589e\u52a0\u4e86BUG\u5b9a\u4f4d\u7684\u590d\u6742\u6027\uff0c\u4f46\u51cf\u5c11\u4e86\u5f00\u53d1\u4eba\u5458\u9700\u8981\u505a\u51fa\u51b3\u5b9a\u7684\u6570\u91cf\uff0c\u540c\u65f6\u51cf\u5c11\u4e86\u5927\u91cf\u7684XML\u914d\u7f6e\uff0c\u5e76\u4e14\u53ef\u4ee5\u5c06\u4ee3\u7801\u7f16\u8bd1\u3001\u6d4b\u8bd5\u548c\u6253\u5305\u7b49\u5de5\u4f5c\u81ea\u52a8\u5316\u3002<\/strong><\/p>\n\n\n\n<p>\u90a3\u4e48\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u7684\u6240\u6709\u4e1c\u897f\uff0c\u5c31\u5e94\u8be5\u4ece\u8fd9\u4e24\u4e2a\u7279\u70b9\u51fa\u53d1\uff0c\u4e00\u6b65\u4e00\u6b65\u6df1\u5165SpringBoot\u81ea\u52a8\u88c5\u914d\u7684\u539f\u7406\u3002<\/p>\n\n\n\n<p><strong>\u5f00\u7bb1\u5373\u7528\u539f\u7406<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u8981\u7406\u89e3\u8fd9\u4e00\u7279\u70b9\uff0c\u9996\u5148\u8981\u5148\u81ea\u5df1\u4f53\u4f1a\u5f00\u7bb1\u5373\u7528\u7684\u6574\u4e2a\u8fc7\u7a0b\u5e26\u6765\u7684\u4fbf\u5229\u3002<\/p>\n\n\n\n<p><strong>\u4f53\u9a8c\u5f00\u7bb1\u5373\u7528<\/strong><\/p>\n\n\n\n<p>SpringBoot\u63d0\u4f9b\u4e86\u6211\u4eec\u5feb\u901f\u521b\u5efaSpringBoot\u9879\u76ee\u7684\u5730\u65b9\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/start.spring.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/start.spring.io\/<\/a><\/p>\n\n\n\n<p>\u6211\u4eec\u53ea\u9700\u8981\u5728\u8fd9\u4e2a\u7f51\u9875\u4e2d\u628a\u6574\u4e2a\u9879\u76ee\u8d77\u597d\u540d\u5b57\uff0c\u7136\u540e\u9009\u597d\u6211\u4eec\u9700\u8981\u7684\u7ec4\u4ef6\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u83b7\u5f97\u4e00\u4e2a\u53ef\u4ee5\u8dd1\u8d77\u6765\u7684SpringBoot\u9879\u76ee\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-270-1024x862.png\" alt=\"\" class=\"wp-image-10857\" width=\"380\" height=\"320\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-1024x862.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-300x252.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-768x646.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-830x698.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-230x194.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-350x295.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270-480x404.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-270.png 1110w\" sizes=\"(max-width: 380px) 100vw, 380px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u53ea\u9700\u8981\u586b\u5b8c\u4e0a\u8ff0\u4fe1\u606f\uff0c\u70b9\u51fbGenerate\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u4e00\u4e2aSpringBoot\u9879\u76ee\u4e0b\u8f7d\u4e0b\u6765\uff0c\u7136\u540e\u5bfc\u5165\u6211\u4eec\u7684IDE\uff0cEclipse\u6216\u8005IDEA\u90fd\u53ef\uff0c\u4e4b\u540e\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u5b83\u8fd0\u884c\u8d77\u6765\u3002<\/p>\n\n\n\n<ul><li>\u5168\u9879\u76ee\u7ed3\u6784\uff1a<\/li><\/ul>\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-271.png\" alt=\"\" class=\"wp-image-10858\" width=\"350\" height=\"306\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271.png 802w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271-300x262.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271-768x670.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271-230x201.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271-350x305.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-271-480x419.png 480w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/figure><\/div>\n\n\n\n<p>\u542f\u52a8\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-272-1024x313.png\" alt=\"\" class=\"wp-image-10859\" width=\"560\" height=\"170\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-1024x313.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-300x92.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-768x235.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-830x254.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-230x70.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-350x107.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272-480x147.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-272.png 1158w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\u8bbf\u95ee\uff1ahttp:\/\/localhost:8080\/ SpringBoot\u9879\u76ee\u542f\u52a8\u6210\u529f\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u5f00\u7bb1\u5373\u7528\u539f\u7406\u5256\u6790<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u5bf9\u6bd4SSM\u914d\u7f6e<\/strong><\/p>\n\n\n\n<p>\u5176\u5b9e\u5728\u4e0a\u6587\u7684\u5f00\u7bb1\u5373\u7528\u4e2d\uff0c\u6211\u4eec\u76f8\u5f53\u4e8e\u5f15\u5165\u4e86\u4e00\u4e2aSpringMVC\u7684\u7ec4\u4ef6\uff0c\u4f46\u662f\u5927\u5bb6\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u6ca1\u6709\u7ecf\u8fc7\u4efb\u4f55\u7684\u914d\u7f6e\u5c31\u5c06\u9879\u76ee\u542f\u52a8\u4e86\u3002\u53cd\u89c2\u8fc7\u53bbSSM\u6846\u67b6\u7684SpringMVC\u914d\u7f6e\uff0c\u6211\u8fd9\u91cc\u6709\u4e00\u4efd\u7559\u5b58\u7684\u5927\u5bb6\u53ef\u4ee5\u5bf9\u6bd4\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p>spring-web.xml:<\/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;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n    xmlns:mvc=\"http:\/\/www.springframework.org\/schema\/mvc\"\n    xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans\n    http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\n    http:\/\/www.springframework.org\/schema\/context\n    http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\n    http:\/\/www.springframework.org\/schema\/mvc\n    http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc-3.2.xsd\">\n    &lt;!-- \u914d\u7f6eSpringMVC -->\n    &lt;!-- 1.\u5f00\u542fSpringMVC\u6ce8\u89e3\u6a21\u5f0f -->\n    &lt;!-- \u7b80\u5316\u914d\u7f6e\uff1a (1)\u81ea\u52a8\u6ce8\u518cDefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter\n        (2)\u63d0\u4f9b\u4e00\u4e9b\u5217\uff1a\u6570\u636e\u7ed1\u5b9a\uff0c\u6570\u5b57\u548c\u65e5\u671f\u7684format @NumberFormat, @DateTimeFormat, xml,json\u9ed8\u8ba4\u8bfb\u5199\u652f\u6301 -->\n    &lt;mvc:annotation-driven \/>\n\n    &lt;!-- 2.\u9759\u6001\u8d44\u6e90\u9ed8\u8ba4servlet\u914d\u7f6e (1)\u52a0\u5165\u5bf9\u9759\u6001\u8d44\u6e90\u7684\u5904\u7406\uff1ajs,gif,png (2)\u5141\u8bb8\u4f7f\u7528\"\/\"\u505a\u6574\u4f53\u6620\u5c04 -->\n    &lt;mvc:resources mapping=\"\/resources\/**\" location=\"\/resources\/\" \/>\n    &lt;mvc:default-servlet-handler \/>\n\n    &lt;!-- 3.\u5b9a\u4e49\u89c6\u56fe\u89e3\u6790\u5668 -->\n    &lt;bean id=\"viewResolver\"\n        class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\">\n        &lt;property name=\"prefix\" value=\"\/WEB-INF\/html\/\">&lt;\/property>\n        &lt;property name=\"suffix\" value=\".html\">&lt;\/property>\n    &lt;\/bean>\n    &lt;!-- \u6587\u4ef6\u4e0a\u4f20\u89e3\u6790\u5668 -->\n    &lt;bean id=\"multipartResolver\"\n        class=\"org.springframework.web.multipart.commons.CommonsMultipartResolver\">\n        &lt;property name=\"defaultEncoding\" value=\"utf-8\">&lt;\/property>\n        &lt;property name=\"maxUploadSize\" value=\"10485760000\">&lt;\/property>&lt;!-- \u6700\u5927\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f -->\n        &lt;property name=\"maxInMemorySize\" value=\"20971520\">&lt;\/property>\n    &lt;\/bean>\n    &lt;!-- \u5728spring-mvc.xml\u6587\u4ef6\u4e2d\u52a0\u5165\u8fd9\u6bb5\u914d\u7f6e\u540e\uff0cspring\u8fd4\u56de\u7ed9\u9875\u9762\u7684\u90fd\u662futf-8\u7f16\u7801\u4e86 -->\n    &lt;bean\n        class=\"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter\">\n        &lt;property name=\"messageConverters\">\n            &lt;list>\n                &lt;bean\n                    class=\"org.springframework.http.converter.StringHttpMessageConverter\">\n                    &lt;property name=\"supportedMediaTypes\">\n                        &lt;list>\n                            &lt;value>text\/html;charset=UTF-8&lt;\/value>\n                        &lt;\/list>\n                    &lt;\/property>\n                &lt;\/bean>\n            &lt;\/list>\n        &lt;\/property>\n    &lt;\/bean>\n    &lt;!-- 4.\u626b\u63cfweb\u76f8\u5173\u7684bean -->\n    &lt;context:component-scan base-package=\"com.SchoolShop.o2o.web\" \/>\n    &lt;!-- 5.\u6743\u9650\u62e6\u622a\u5668 -->\n&lt;\/beans><\/pre>\n\n\n\n<p>web.xml:<\/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;servlet>\n      &lt;servlet-name>spring-dispatcher&lt;\/servlet-name>\n      &lt;servlet-class>org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class>\n      &lt;init-param>\n          &lt;param-name>contextConfigLocation&lt;\/param-name>\n          &lt;param-value>classpath:spring\/spring-*.xml&lt;\/param-value>\n      &lt;\/init-param>\n  &lt;\/servlet>\n  &lt;servlet-mapping>\n      &lt;servlet-name>spring-dispatcher&lt;\/servlet-name>\n      &lt;!-- \u9ed8\u8ba4\u5339\u914d\u6240\u6709\u8bf7\u6c42 -->\n      &lt;url-pattern>\/&lt;\/url-pattern>\n  &lt;\/servlet-mapping>\n\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u91cc\u9700\u8981\u914d\u7f6e\u4e24\u4e2a\u6587\u4ef6\uff0cweb.xml\u548cspring-web.xml\uff0c\u914d\u7f6e\u53ef\u4ee5\u8bf4\u662f\u76f8\u5f53\u7e41\u91cd\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u76f8\u5bf9\u4e8e\u8fd9\u4e2a\uff0cSpringBoot\u7684\u5f00\u7bb1\u5373\u7528\u5c31\u663e\u5f97\u7279\u522b\u65b9\u4fbf\uff0c\u90a3\u4e48\u6211\u4eec\u7740\u91cd\u804a\u804aSpringBoot\u5f00\u7bb1\u5373\u7528\u7684\u539f\u7406\u3002<\/p>\n\n\n\n<p><strong>\u4ecepom.xml\u5f00\u59cb<\/strong><\/p>\n\n\n\n<p>SpringBoot\u7684\u9879\u76ee\u90fd\u4f1a\u5b58\u5728\u4e00\u4e2a\u7236\u4f9d\u8d56\uff0c\u6309\u4f4fCtrl+\u9f20\u6807\u5de6\u952e\uff0c\u53ef\u4ee5\u70b9\u8fdb\u53bb\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=\"\">&lt;parent>\n    &lt;groupId>org.springframework.boot&lt;\/groupId>\n    &lt;artifactId>spring-boot-starter-parent&lt;\/artifactId>\n    &lt;version>2.2.1.RELEASE&lt;\/version>\n    &lt;relativePath\/> &lt;!-- lookup parent from repository -->\n&lt;\/parent><\/pre>\n\n\n\n<p>\u70b9\u8fdb\u53bb\u4e4b\u540e\u53d1\u73b0\u91cc\u9762\u9664\u4e86\u4e00\u4e9b\u63d2\u4ef6\u548c\u914d\u7f6e\u6587\u4ef6\u7684\u683c\u5f0f\u4e4b\u5916\uff0c\u8fd8\u5b58\u5728\u4e00\u4e2a\u4f9d\u8d56\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=\"\">&lt;parent>\n    &lt;groupId>org.springframework.boot&lt;\/groupId>\n    &lt;artifactId>spring-boot-dependencies&lt;\/artifactId>\n    &lt;version>2.2.1.RELEASE&lt;\/version>\n    &lt;relativePath>..\/..\/spring-boot-dependencies&lt;\/relativePath>\n&lt;\/parent><\/pre>\n\n\n\n<p>\u4e8e\u662f\u518d\u70b9\u8fdb\u53bb\uff0c\u53ef\u4ee5\u53d1\u73b0\u91cc\u9762\u653e\u4e86\u5f88\u591a\u7684\u4f9d\u8d56\u548c\u4f9d\u8d56\u7684\u7248\u672c\u53f7\u3002\u7531\u4e8e\u8fd9\u4e2a\u6587\u4ef6\u5b9e\u5728\u592a\u957f\u4e86\uff0c\u6240\u4ee5\u8fd9\u91cc\u53ea\u5c55\u793a\u4e00\u90e8\u5206\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-273.png\" alt=\"\" class=\"wp-image-10860\" width=\"499\" height=\"273\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273.png 1020w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-768x420.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-830x454.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-273-480x263.png 480w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/figure><\/div>\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-286.png\" alt=\"\" class=\"wp-image-10877\" width=\"271\" height=\"278\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286.png 878w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-291x300.png 291w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-768x791.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-830x855.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-230x237.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-350x360.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-286-480x494.png 480w\" sizes=\"(max-width: 271px) 100vw, 271px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u7b2c\u4e00\u4e2a\u7ed3\u8bba\uff1a<\/strong><\/p>\n\n\n\n<p>spring-boot-dependencies:\u4f5c\u4e3a\u7236\u5de5\u7a0b\uff0c\u5b58\u653e\u4e86SpringBoot\u7684\u6838\u5fc3\u4f9d\u8d56\u3002\u6211\u4eec\u5728\u5199\u6216\u8005\u5f15\u5165\u4e00\u4e9bSpringBoot\u4f9d\u8d56\u7684\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u6307\u5b9a\u7248\u672c\uff0c\u6b63\u662f\u56e0\u4e3aSpringBoot\u7684\u7236\u4f9d\u8d56\u5df2\u7ecf\u5e2e\u6211\u4eec\u7ef4\u62a4\u4e86\u4e00\u5957\u7248\u672c\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u7236\u4f9d\u8d56\u4e2d\u4e5f\u5e2e\u6211\u4eec\u5199\u597d\u4e86\u8d44\u6e90\u5e93\uff0c\u4e0d\u7528\u6211\u4eec\u81ea\u5df1\u518d\u53bb\u914d\u7f6e\u4e86\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=\"\">&lt;resources>\n      &lt;resource>\n        &lt;filtering>true&lt;\/filtering>\n        &lt;directory>${basedir}\/src\/main\/resources&lt;\/directory>\n        &lt;includes>\n            &lt;!-- \u53ef\u4ee5\u8bfb\u53d6\u7684\u914d\u7f6e\u6587\u4ef6\u6709\n                application.yml\/application.yaml\/application.properties\n             -->\n          &lt;include>**\/application*.yml&lt;\/include>\n          &lt;include>**\/application*.yaml&lt;\/include>\n          &lt;include>**\/application*.properties&lt;\/include>\n        &lt;\/includes>\n      &lt;\/resource>\n      &lt;resource>\n        &lt;directory>${basedir}\/src\/main\/resources&lt;\/directory>\n        &lt;excludes>\n          &lt;exclude>**\/application*.yml&lt;\/exclude>\n          &lt;exclude>**\/application*.yaml&lt;\/exclude>\n          &lt;exclude>**\/application*.properties&lt;\/exclude>\n        &lt;\/excludes>\n      &lt;\/resource>\n&lt;\/resources>\n<\/pre>\n\n\n\n<p><strong>\u542f\u52a8\u5668<\/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=\"\">&lt;dependency>\n    &lt;groupId>org.springframework.boot&lt;\/groupId>\n    &lt;artifactId>spring-boot-starter&lt;\/artifactId>\n    &lt;version>2.2.1.RELEASE&lt;\/version>\n&lt;\/dependency>\n<\/pre>\n\n\n\n<p>\u542f\u52a8\u5668\u5c31\u662fSpringBoot\u7684\u542f\u52a8\u573a\u666f\uff0c\u6bd4\u5982\u6211\u4eec\u8981\u4f7f\u7528web\u76f8\u5173\u7684\uff0c\u90a3\u4e48\u5c31\u76f4\u63a5\u5f15\u5165spring-boor-starter-web\uff0c\u90a3\u4e48\u4ed6\u5c31\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u5bfc\u5165web\u73af\u5883\u4e0b\u6240\u6709\u5fc5\u9700\u7684\u4f9d\u8d56\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u6765\u770b\u770b\u542f\u52a8\u5668\u4e2d\u5b58\u653e\u4e86\u4e00\u4e9b\u4ec0\u4e48\u5185\u5bb9\uff1a<\/p>\n\n\n\n<p>\u4ee5spring-boot-starter\u4e3a\u4f8b\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>org.springframework.boot&lt;\/groupId>\n      &lt;artifactId>spring-boot&lt;\/artifactId>\n      &lt;version>2.2.1.RELEASE&lt;\/version>\n      &lt;scope>compile&lt;\/scope>\n    &lt;\/dependency>\n    &lt;dependency>\n      &lt;groupId>org.springframework.boot&lt;\/groupId>\n      &lt;artifactId>spring-boot-autoconfigure&lt;\/artifactId>\n      &lt;version>2.2.1.RELEASE&lt;\/version>\n      &lt;scope>compile&lt;\/scope>\n    &lt;\/dependency>\n    &lt;dependency>\n      &lt;groupId>org.springframework.boot&lt;\/groupId>\n      &lt;artifactId>spring-boot-starter-logging&lt;\/artifactId>\n      &lt;version>2.2.1.RELEASE&lt;\/version>\n      &lt;scope>compile&lt;\/scope>\n    &lt;\/dependency>\n    &lt;dependency>\n      &lt;groupId>jakarta.annotation&lt;\/groupId>\n      &lt;artifactId>jakarta.annotation-api&lt;\/artifactId>\n      &lt;version>1.3.5&lt;\/version>\n      &lt;scope>compile&lt;\/scope>\n    &lt;\/dependency>\n    &lt;dependency>\n      &lt;groupId>org.springframework&lt;\/groupId>\n      &lt;artifactId>spring-core&lt;\/artifactId>\n      &lt;version>5.2.1.RELEASE&lt;\/version>\n      &lt;scope>compile&lt;\/scope>\n    &lt;\/dependency>\n    &lt;dependency>\n      &lt;groupId>org.yaml&lt;\/groupId>\n      &lt;artifactId>snakeyaml&lt;\/artifactId>\n      &lt;version>1.25&lt;\/version>\n      &lt;scope>runtime&lt;\/scope>\n    &lt;\/dependency>\n<\/pre>\n\n\n\n<p>\u5176\u4e2d\u5b58\u653e\u4e86\u81ea\u52a8\u914d\u7f6e\u76f8\u5173\u7684\u4f9d\u8d56\u3001\u65e5\u5fd7\u76f8\u5173\u4f9d\u8d56\u3001\u8fd8\u6709Spring-core\u7b49\u4f9d\u8d56\uff0c\u8fd9\u4e9b\u4f9d\u8d56\u6211\u4eec\u53ea\u9700\u8981\u5bfc\u5165\u4e00\u4e2aspring-boor-starter\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u5176\u5168\u90e8\u5f15\u5165\uff0c\u800c\u4e0d\u9700\u8981\u518d\u50cf\u4ee5\u524d\u90a3\u6837\u9010\u4e2a\u5bfc\u5165\u4e86\u3002<\/p>\n\n\n\n<p><strong>SpringBoot\u4f1a\u5c06\u6240\u6709\u7684\u529f\u80fd\u573a\u666f\u90fd\u5c01\u88c5\u6210\u4e00\u4e2a\u4e00\u4e2a\u7684\u542f\u52a8\u5668\uff0c\u4f9b\u5f00\u53d1\u4eba\u5458\u4f7f\u7528\u3002<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u5728\u4f7f\u7528\u7684\u65f6\u5019\u4e5f\u53ef\u4ee5\u76f4\u63a5\u53bb\u5b98\u7f51\u4e0a\u627e\u6211\u4eec\u6240\u9700\u7684\u542f\u52a8\u5668\uff0c\u76f4\u63a5\u5c06\u5176\u5f15\u5165\u3002<\/p>\n\n\n\n<p>\u83b7\u53d6\u542f\u52a8\u5668\u6587\u6863\uff1a<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/docs.spring.io\/spring-boot\/docs\/2.2.1.RELEASE\/reference\/html\/using-spring-boot.html%23using-boot-starter\" target=\"_blank\">docs.spring.io\/spring-boot\/docs\/2.2.1.RELEASE\/reference\/html\/using-spring-boot.html#using-boot-starter<\/a><\/p>\n\n\n\n<p><strong>\u4e3b\u7a0b\u5e8f\uff08\u91cd\u8981\uff09<\/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=\"\">\/\/@SpringBootApplication \u6807\u6ce8\uff0c\u662f\u4e00\u4e2aSpringBoot\u5e94\u7528\n@SpringBootApplication\npublic class SpringbootdemoApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(SpringbootdemoApplication.class, args);\n    }\n}\n<\/pre>\n\n\n\n<p>\u518d\u5199SpringBoot\u9879\u76ee\u7684\u65f6\u5019\uff0c\u603b\u8981\u5199\u8fd9\u4e48\u4e00\u4e2a\u4e3b\u7a0b\u5e8f\uff0c\u8fd9\u4e2a\u4e3b\u7a0b\u5e8f\u6700\u5927\u7684\u7279\u70b9\u5c31\u662f\u5176\u7c7b\u4e0a\u653e\u4e86\u4e00\u4e2a@SpringBootApplication\u6ce8\u89e3\uff0c\u8fd9\u4e5f\u6b63\u662fSpringBoot\u9879\u76ee\u542f\u52a8\u7684\u6838\u5fc3\uff0c\u4e5f\u662f\u6211\u4eec\u8981\u7814\u7a76\u7684\u91cd\u70b9\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a\u4e4b\u540e\u7684\u5206\u6790\u53ef\u80fd\u4f1a\u6df1\u5165\u6e90\u7801\uff0c\u6e90\u7801\u662f\u4e00\u5c42\u4e00\u5c42\u5d4c\u5957\u7684\uff0c\u6240\u4ee5\u5149\u9760\u6587\u5b57\u8bf4\u660e\u4f1a\u6bd4\u8f83\u96be\u4ee5\u7406\u89e3\uff0c\u6700\u597d\u662f\u81ea\u5df1\u5728IDE\u73af\u5883\u4e0b\u8ddf\u7740\u4e00\u6b65\u4e00\u6b65\u8ddf\u7740\u70b9\u4e0b\u53bb\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u7ed5\u8fc7\u8fd9\u4e00\u90e8\u5206\u76f4\u63a5\u770b\u7ed3\u8bba\u3002<\/strong><\/p>\n\n\n\n<p>\u70b9\u5f00@SpringBootApplication\uff0c\u53ef\u4ee5\u53d1\u73b0\u5b83\u662f\u4e00\u4e2a\u7ec4\u5408\u6ce8\u89e3\uff0c\u4e3b\u8981\u662f\u7531\u8fd9\u4e48\u51e0\u4e2a\u6ce8\u89e3\u6784\u6210\u7684\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=\"\">@SpringBootConfiguration\/\/\u6838\u5fc3\n@EnableAutoConfiguration\/\/\u6838\u5fc3\n@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),\n        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })<\/pre>\n\n\n\n<p>\u6211\u4eec\u9996\u5148\u8981\u7814\u7a76\u7684\u5c31\u662f\u6838\u5fc3\u7684\u4e24\u4e2a\u6ce8\u89e3 <strong>@SpringBootConfiguration<\/strong>\u548c<strong>@EnableAutoConfiguration<\/strong>\uff0c\u9010\u4e2a\u8fdb\u884c\u5206\u6790\u3002<\/p>\n\n\n\n<p><code><strong>@SpringBootConfiguration<\/strong><\/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=\"\">@Target(ElementType.TYPE)\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Configuration\npublic @interface SpringBootConfiguration {\n}\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230SpringBootConfiguration\u5176\u5b9e\u5c31\u643a\u5e26\u4e86\u4e00\u4e2a@Configuration\u6ce8\u89e3\uff0c\u8fd9\u4e2a\u6ce8\u89e3\u6211\u4eec\u518d\u719f\u6089\u4e0d\u8fc7\u4e86\uff0c\u4ed6\u5c31\u4ee3\u8868\u81ea\u5df1\u662f\u4e00\u4e2aSpring\u7684\u914d\u7f6e\u7c7b\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u8ba4\u4e3a\uff1a@SpringBootConfiguration = @Configuration<\/p>\n\n\n\n<p><code><strong>@EnableAutoConfiguration<\/strong><\/code><\/p>\n\n\n\n<p>\u987e\u540d\u601d\u4e49\uff0c\u8fd9\u4e2a\u6ce8\u89e3\u4e00\u5b9a\u548c\u81ea\u52a8\u914d\u7f6e\u76f8\u5173\uff0c\u70b9\u8fdb\u53bb\u770b\u6e90\u4ee3\u7801\u4e4b\u540e\u53ef\u4ee5\u53d1\u73b0\uff0c\u5176\u5185\u90e8\u5c31\u5305\u542b\u4e86\u8fd9\u4e48\u4e24\u4e2a\u6ce8\u89e3\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=\"\">@AutoConfigurationPackage \/\/\u81ea\u52a8\u914d\u7f6e\u5305\n@Import(AutoConfigurationImportSelector.class)\/\/\u81ea\u52a8\u914d\u7f6e\u5bfc\u5165\u9009\u62e9<\/pre>\n\n\n\n<p>\u6765\u770b\u770b<code>@Import(AutoConfigurationImportSelector.class)<\/code>\u4e2d\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<p>\u5b83\u5e2e\u6211\u4eec\u5bfc\u5165\u4e86AutoConfigurationImportSelector\uff0c\u8fd9\u4e2a\u7c7b\u4e2d\u5b58\u5728\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u6211\u4eec\u83b7\u53d6\u6240\u6709\u7684\u914d\u7f6e\uff0c\u4ee3\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=\"\">\/*\n  \u6240\u6709\u7684\u914d\u7f6e\u90fd\u5b58\u653e\u5728configurations\u4e2d\uff0c\n  \u800c\u8fd9\u4e9b\u914d\u7f6e\u90fd\u4ecegetCandidateConfiguration\u4e2d\u83b7\u53d6\uff0c\n  \u8fd9\u4e2a\u65b9\u6cd5\u662f\u7528\u6765\u83b7\u53d6\u5019\u9009\u7684\u914d\u7f6e\u3002\n*\/\nList&lt;String> configurations = getCandidateConfigurations(annotationMetadata, attributes);\n<\/pre>\n\n\n\n<p><strong>getCandidateConfigurations():<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u6240\u6709\u5019\u9009\u7684\u914d\u7f6e\uff0c\u90a3\u4e48\u8fd9\u4e9b\u5019\u9009\u7684\u914d\u7f6e\u53c8\u662f\u4ece\u54ea\u6765\u7684\u5462\uff1f<\/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=\"\">\/*\u83b7\u53d6\u5019\u9009\u7684\u914d\u7f6e*\/\nprotected List&lt;String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {\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>\u5b9e\u9645\u4e0a\u5b83\u8fd4\u56de\u4e86\u4e00\u4e2aList\uff0c\u8fd9\u4e2aList\u662f\u7531<strong>loadFactoryNames()<\/strong>\u65b9\u6cd5\u8fd4\u56de\u7684,\u5176\u4e2d\u4f20\u5165\u4e86\u4e00\u4e2agetSpringFactoriesLoaderFactoryClass()\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u770b\u8fd9\u4e2a\u65b9\u6cd5\u7684\u5185\u5bb9\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=\"\">protected Class&lt;?> getSpringFactoriesLoaderFactoryClass() {\n    return EnableAutoConfiguration.class;\n}\n<\/pre>\n\n\n\n<p>\u6211\u4eec\u770b\u5230\u4e86\u4e00\u4e2a\u773c\u719f\u7684\u8bcd \u2014\u2014 <strong>EnableAutoConfiguration<\/strong>\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u5b9e\u9645\u4e0a\u8fd4\u56de\u7684\u5c31\u662f\u6807\u6ce8\u4e86\u8fd9\u4e2a\u7c7b\u7684\u6240\u6709\u5305\u3002\u6807\u6ce8\u4e86\u8fd9\u4e2a\u7c7b\u7684\u5305\u4e0d\u5c31\u662f<code>@SpringBootApplication<\/code>\u5417\uff1f<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u7ed3\u8bba\uff1a\u5b83\u515c\u515c\u8f6c\u8f6c\u7ed5\u4e86\u8fd9\u4e48\u591a\u5730\u65b9\uff0c\u5c31\u662f\u4e3a\u4e86\u5c06\u542f\u52a8\u7c7b\u6240\u9700\u7684\u6240\u6709\u8d44\u6e90\u5bfc\u5165\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u63a5\u7740\u5f80\u4e0b\u770b\uff0c\u5b83\u5176\u4e2d\u8fd8\u6709\u8fd9\u4e48\u4e00\u6761\u8bed\u53e5\uff0c\u662f\u4e00\u6761\u65ad\u8a00\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">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.\");<\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u65ad\u8a00\u7684\u610f\u601d\u662f\uff0cconfigurations\u5fc5\u987b\u975e\u7a7a\uff0c\u5426\u5219\u5c31\u6253\u5370\u4e00\u6bb5\u8bdd\uff0c<code>No auto configuration classes found in META-INF\/spring.factories<\/code>\uff0c\u6211\u4eec\u628a\u8fd9\u4e2a\u903b\u8f91\u53cd\u8fc7\u6765\u60f3\u60f3\u3002\u5982\u679c\u8fd9\u4e2a\u96c6\u5408\u4e0d\u4e3a\u7a7a\uff0c\u662f\u4e0d\u662f\u5c31\u4ee3\u8868\u627e\u5230\u4e86\u8fd9\u4e2aspring.factories\u5e76\u4e14\u4f1a\u53bb\u52a0\u8f7d\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u5462\uff1f<\/p>\n\n\n\n<p>\u5e26\u7740\u8fd9\u4e2a\u7591\u95ee\uff0c\u6211\u4eec\u9996\u5148\u627e\u5230spring.factories\u8fd9\u4e2a\u6587\u4ef6\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-275.png\" alt=\"\" class=\"wp-image-10862\" width=\"435\" height=\"136\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275.png 1002w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-300x95.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-768x242.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-830x262.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-230x73.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-350x110.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-275-480x151.png 480w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u91cc\u9762\u5305\u542b\u4e86\u5f88\u591a\u81ea\u52a8\u914d\u7f6e\u5c5e\u6027\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-276-1024x851.png\" alt=\"\" class=\"wp-image-10863\" width=\"424\" height=\"352\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-1024x851.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-300x249.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-768x638.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-830x690.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-230x191.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-350x291.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276-480x399.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-276.png 1102w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u968f\u4fbf\u627e\u4e00\u4e2a\u81ea\u52a8\u914d\u7f6e\u70b9\u8fdb\u53bb,\u6bd4\u5982<code>WebMvcAutoConfiguration<\/code>\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-277-1024x693.png\" alt=\"\" class=\"wp-image-10864\" width=\"499\" height=\"337\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-1024x693.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-300x203.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-768x519.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-830x561.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-230x156.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-350x237.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277-480x325.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-277.png 1106w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u91cc\u653e\u4e86\u6240\u6709\u5173\u4e8eWebMvc\u7684\u914d\u7f6e\uff0c\u5982\u89c6\u56fe\u89e3\u6790\u5668\u3001\u56fd\u9645\u5316\u7b49\u7b49\u3002<\/p>\n\n\n\n<p>\u5206\u6790\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u51fa\u4e00\u4e2a\u5b8c\u6574\u7684\u7ed3\u8bba\u4e86\uff1a<\/p>\n\n\n\n<p><strong>\u5f53\u6211\u4eec\u7684SpringBoot\u9879\u76ee\u542f\u52a8\u7684\u65f6\u5019\uff0c\u4f1a\u5148\u5bfc\u5165AutoConfigurationImportSelector\uff0c\u8fd9\u4e2a\u7c7b\u4f1a\u5e2e\u6211\u4eec\u9009\u62e9\u6240\u6709\u5019\u9009\u7684\u914d\u7f6e\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u7684\u914d\u7f6e\u90fd\u662fSpringBoot\u5e2e\u6211\u4eec\u5199\u597d\u7684\u4e00\u4e2a\u4e00\u4e2a\u7684\u914d\u7f6e\u7c7b\uff0c\u90a3\u4e48\u8fd9\u4e9b\u914d\u7f6e\u7c7b\u7684\u4f4d\u7f6e\uff0c\u5b58\u5728\u4e0eMETA-INF\/spring.factories\u6587\u4ef6\u4e2d\uff0c\u901a\u8fc7\u8fd9\u4e2a\u6587\u4ef6\uff0cSpring\u53ef\u4ee5\u627e\u5230\u8fd9\u4e9b\u914d\u7f6e\u7c7b\u7684\u4f4d\u7f6e\uff0c\u4e8e\u662f\u53bb\u52a0\u8f7d\u5176\u4e2d\u7684\u914d\u7f6e\u3002<\/strong><\/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-278.png\" alt=\"\" class=\"wp-image-10865\" width=\"260\" height=\"366\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-278.png 658w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-278-213x300.png 213w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-278-230x324.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-278-350x493.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-278-480x676.png 480w\" sizes=\"(max-width: 260px) 100vw, 260px\" \/><\/figure><\/div>\n\n\n\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u53ef\u80fd\u6709\u4e9b\u540c\u5b66\u4f1a\u5b58\u5728\u7591\u95ee\uff0cspring.factories\u4e2d\u5b58\u5728\u90a3\u4e48\u591a\u7684\u914d\u7f6e\uff0c\u6bcf\u6b21\u542f\u52a8\u65f6\u90fd\u662f\u628a\u5b83\u4eec\u5168\u91cf\u52a0\u8f7d\u5417\uff1f\u8fd9\u663e\u7136\u662f\u4e0d\u73b0\u5b9e\u7684\u3002<\/p>\n\n\n\n<p>\u8fd9\u5176\u5b9e\u4e5f\u662f\u6211\u5728\u770b\u6e90\u7801\u7684\u65f6\u5019\u5b58\u5728\u7591\u95ee\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u5176\u4e2d\u6709\u4e00\u4e2a\u6ce8\u89e3\u5e76\u4e0d\u5e38\u7528\uff0c\u6211\u4eec\u70b9\u5f00\u4e00\u4e2a\u914d\u7f6e\u7c7b\u5c31\u53ef\u4ee5\u770b\u5230\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-279-1024x157.png\" alt=\"\" class=\"wp-image-10866\" width=\"570\" height=\"86\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-279-1024x157.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-279-300x46.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-279-830x127.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-279-230x35.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-279-350x54.png 350w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure><\/div>\n\n\n\n<p>@ConditionalOnXXX:\u5982\u679c\u5176\u4e2d\u7684\u6761\u4ef6\u90fd\u6ee1\u8db3\uff0c\u8be5\u7c7b\u624d\u4f1a\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5728\u52a0\u8f7d\u81ea\u52a8\u914d\u7f6e\u7c7b\u7684\u65f6\u5019\uff0c\u5e76\u4e0d\u662f\u5c06spring.factories\u7684\u914d\u7f6e\u5168\u91cf\u52a0\u8f7d\u8fdb\u6765\uff0c\u800c\u662f\u901a\u8fc7\u8fd9\u4e2a\u6ce8\u89e3\u7684\u5224\u65ad\uff0c\u5982\u679c\u6ce8\u89e3\u4e2d\u7684\u7c7b\u90fd\u5b58\u5728\uff0c\u624d\u4f1a\u8fdb\u884c\u52a0\u8f7d\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5c31\u5b9e\u73b0\u4e86\uff1a\u6211\u4eec\u5728pom.xml\u6587\u4ef6\u4e2d\u52a0\u5165stater\u542f\u52a8\u5668\uff0cSpringBoot\u81ea\u52a8\u8fdb\u884c\u914d\u7f6e\u3002\u5b8c\u6210\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>SpringBoot\u6240\u6709\u81ea\u52a8\u914d\u7f6e\u7c7b\u90fd\u662f\u5728\u542f\u52a8\u7684\u65f6\u5019\u8fdb\u884c\u626b\u63cf\u5e76\u52a0\u8f7d\uff0c\u901a\u8fc7spring.factories\u53ef\u4ee5\u627e\u5230\u81ea\u52a8\u914d\u7f6e\u7c7b\u7684\u8def\u5f84\uff0c\u4f46\u662f\u4e0d\u662f\u6240\u6709\u5b58\u5728\u4e8espring,factories\u4e2d\u7684\u914d\u7f6e\u90fd\u8fdb\u884c\u52a0\u8f7d\uff0c\u800c\u662f\u901a\u8fc7@ConditionalOnClass\u6ce8\u89e3\u8fdb\u884c\u5224\u65ad\u6761\u4ef6\u662f\u5426\u6210\u7acb\uff08\u53ea\u8981\u5bfc\u5165\u76f8\u5e94\u7684stater\uff0c\u6761\u4ef6\u5c31\u80fd\u6210\u7acb\uff09\uff0c\u5982\u679c\u6761\u4ef6\u6210\u7acb\u5219\u52a0\u8f7d\u914d\u7f6e\u7c7b\uff0c\u5426\u5219\u4e0d\u52a0\u8f7d\u8be5\u914d\u7f6e\u7c7b\u3002<\/p>\n\n\n\n<p>\u5728\u8fd9\u91cc\u8d34\u4e00\u4e2a\u6211\u8ba4\u4e3a\u7684\u6bd4\u8f83\u5bb9\u6613\u7406\u89e3\u7684\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<ul><li>SpringBoot\u5728\u542f\u52a8\u7684\u65f6\u5019\u4ece\u7c7b\u8def\u5f84\u4e0b\u7684META-INF\/spring.factories\u4e2d\u83b7\u53d6EnableAutoConfiguration\u6307\u5b9a\u7684\u503c<\/li><li>\u5c06\u8fd9\u4e9b\u503c\u4f5c\u4e3a\u81ea\u52a8\u914d\u7f6e\u7c7b\u5bfc\u5165\u5bb9\u5668 \uff0c \u81ea\u52a8\u914d\u7f6e\u7c7b\u5c31\u751f\u6548 \uff0c \u5e2e\u6211\u4eec\u8fdb\u884c\u81ea\u52a8\u914d\u7f6e\u5de5\u4f5c\uff1b<\/li><li>\u4ee5\u524d\u6211\u4eec\u9700\u8981\u81ea\u5df1\u914d\u7f6e\u7684\u4e1c\u897f \uff0c \u81ea\u52a8\u914d\u7f6e\u7c7b\u90fd\u5e2e\u6211\u4eec\u89e3\u51b3\u4e86<\/li><li>\u6574\u4e2aJ2EE\u7684\u6574\u4f53\u89e3\u51b3\u65b9\u6848\u548c\u81ea\u52a8\u914d\u7f6e\u90fd\u5728springboot-autoconfigure\u7684jar\u5305\u4e2d\uff1b<\/li><li>\u5b83\u5c06\u6240\u6709\u9700\u8981\u5bfc\u5165\u7684\u7ec4\u4ef6\u4ee5\u5168\u7c7b\u540d\u7684\u65b9\u5f0f\u8fd4\u56de \uff0c \u8fd9\u4e9b\u7ec4\u4ef6\u5c31\u4f1a\u88ab\u6dfb\u52a0\u5230\u5bb9\u5668\u4e2d \uff1b<\/li><li>\u5b83\u4f1a\u7ed9\u5bb9\u5668\u4e2d\u5bfc\u5165\u975e\u5e38\u591a\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b \uff08xxxAutoConfiguration\uff09, \u5c31\u662f\u7ed9\u5bb9\u5668\u4e2d\u5bfc\u5165\u8fd9\u4e2a\u573a\u666f\u9700\u8981\u7684\u6240\u6709\u7ec4\u4ef6 \uff0c \u5e76\u914d\u7f6e\u597d\u8fd9\u4e9b\u7ec4\u4ef6 \uff1b<\/li><li>\u6709\u4e86\u81ea\u52a8\u914d\u7f6e\u7c7b \uff0c \u514d\u53bb\u4e86\u6211\u4eec\u624b\u52a8\u7f16\u5199\u914d\u7f6e\u6ce8\u5165\u529f\u80fd\u7ec4\u4ef6\u7b49\u7684\u5de5\u4f5c\uff1b<\/li><\/ul>\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-281-1024x841.png\" alt=\"\" class=\"wp-image-10868\" width=\"426\" height=\"349\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-1024x841.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-300x247.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-768x631.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-830x682.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-230x189.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-350x288.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281-480x394.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-281.png 1088w\" sizes=\"(max-width: 426px) 100vw, 426px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5f00\u7bb1\u5373\u7528\u7684\u539f\u7406\u8bf4\u5b8c\u4e86\uff0c\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\u5c31\u6bd4\u8f83\u597d\u7406\u89e3\u4e86\u3002\u5176\u5b9e\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\u5c31\u662f\u5f00\u7bb1\u5373\u7528\u4e2d\u90a3\u4e9b\u81ea\u52a8\u914d\u7f6e\u7684\u7ec6\u8282\u3002\u8bf4\u7684\u5177\u4f53\u70b9\u5c31\u662f\uff1a<strong>\u6211\u4eec\u7684\u914d\u7f6e\u6587\u4ef6\uff08.yml\uff09\u5e94\u8be5\u653e\u5728\u54ea\u4e2a\u76ee\u5f55\u4e0b\uff0c\u914d\u7f6e\u6587\u4ef6\u7684\u547d\u540d\u89c4\u8303\uff0c\u9879\u76ee\u542f\u52a8\u65f6\u626b\u63cf\u7684Bean\uff0c\u7ec4\u4ef6\u7684\u9ed8\u8ba4\u914d\u7f6e\u662f\u4ec0\u4e48\u6837\u7684\uff08\u6bd4\u5982SpringMVC\u7684\u89c6\u56fe\u89e3\u6790\u5668\uff09\u7b49\u7b49\u7b49\u7b49\u8fd9\u4e00\u7cfb\u5217\u7684\u4e1c\u897f\uff0c\u90fd\u53ef\u4ee5\u88ab\u79f0\u4e3a\u7ea6\u5b9a<\/strong>\uff0c\u4e0b\u9762\u5c31\u6765\u4e00\u70b9\u4e00\u70b9\u5730\u8bf4\u4e00\u4e0bSpringBoot\u4e2d\u7684\u201c\u7ea6\u5b9a\u201d\u3002<\/p>\n\n\n\n<p><strong>maven\u76ee\u5f55\u7ed3\u6784\u7684\u7ea6\u5b9a<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u53bbSpring\u7684\u5b98\u7f51\u67e5\u770b\u4e00\u4e0b\u5b98\u65b9\u6587\u6863\uff0c\u770b\u770b\u6587\u6863\u4e2d\u63cf\u8ff0\u7684\u76ee\u5f55\u7ed3\u6784\u662f\u600e\u6837\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    Config locations are searched in reverse order. By default, the configured locations are classpath:\/,classpath:\/config\/,file:.\/,file:.\/config\/. The resulting search order is the following:\n<\/pre>\n\n\n\n<ul><li>file:.\/config\/<\/li><li>file:.\/<\/li><li>classpath:\/config\/<\/li><li>classpath:\/<\/li><\/ul>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0cspring\u7684\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\u53ef\u4ee5\u653e\u5728<\/p>\n\n\n\n<ul><li>\/config<\/li><li>\/(\u6839\u76ee\u5f55)<\/li><li>resource\/config\/<\/li><li>resource\/<\/li><\/ul>\n\n\n\n<p>\u8fd9\u56db\u4e2a\u8def\u5f84\u4ece\u4e0a\u5230\u4e0b\u5b58\u5728\u4f18\u5148\u7ea7\u5173\u7cfb\u3002<\/p>\n\n\n\n<p><strong>SpringBoot\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u7684\u7ea6\u5b9a<\/strong><\/p>\n\n\n\n<p>SpringBoot\u9ed8\u8ba4\u53ef\u4ee5\u52a0\u8f7d\u4ee5\u4e0b\u4e09\u79cd\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n\n\n\n<ul><li>application.yml<\/li><li>application.yaml<\/li><li>application.properties<\/li><\/ul>\n\n\n\n<p>\u5efa\u8bae\u4f7f\u7528\u524d\u4e24\u79cd\u4f5c\u4e3a\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p><strong>\u9879\u76ee\u542f\u52a8\u65f6\u626b\u63cf\u5305\u8303\u56f4\u7684\u7ea6\u5b9a<\/strong><\/p>\n\n\n\n<p>SpringBoot\u7684\u6ce8\u89e3\u626b\u63cf\u7684\u9ed8\u8ba4\u89c4\u5219\u662fSpringBoot\u7684\u5165\u53e3\u7c7b\u6240\u5728\u5305\u53ca\u5176\u5b50\u5305\u3002<\/p>\n\n\n\n<p>\u82e5\u5165\u53e3\u7c7b\u6240\u5728\u7684\u5305\u662fcn.objectspace.demo\u90a3\u4e48\u81ea\u52a8\u626b\u63cf\u5305\u7684\u8303\u56f4\u662fcn.objectspace.demo\u5305\u53ca\u5176\u4e0b\u9762\u7684\u5b50\u5305\uff0c\u5982\u679cservice\u5305\u548cdao\u5305\u4e0d\u5728\u6b64\u8303\u56f4\uff0c\u5219\u4e0d\u4f1a\u81ea\u52a8\u626b\u63cf\u3002<\/p>\n\n\n\n<p><strong>SpringBoot\u81ea\u52a8\u914d\u7f6e\u7c7b\u5982\u4f55\u8bfb\u53d6yml\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u4ece\u66f4\u7ec6\u8282\u7684\u89d2\u5ea6\u53bb\u7406\u89e3\u81ea\u52a8\u914d\u7f6e<\/strong><\/p>\n\n\n\n<p>\u4e0a\u6587\u4e2d\u6211\u4eec\u9610\u8ff0\u4e86\u4e00\u4e9bSpringBoot\u81ea\u52a8\u914d\u7f6e\u7684\u539f\u7406\uff0c\u6211\u4eec\u662f\u4ece\u5168\u5c40\u7684\u89d2\u5ea6\u53bb\u770b\u81ea\u52a8\u914d\u7f6e\u7684\u6574\u4e2a\u8fc7\u7a0b\u3002\u6bd4\u5982\u4ece\u54ea\u4e2a\u5730\u65b9\u5f00\u59cb\u8fdb\u884c\u88c5\u914d\u6d41\u7a0b\u3001\u5982\u4f55\u627e\u5230\u88c5\u914d\u7684\u5305\u7b49\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u73b0\u5728\u5c06\u81ea\u5df1\u7684\u89c6\u89d2\u8d34\u8fd1SpringBoot\uff0c\u6765\u804a\u804aapplication.yml\u4e2d\u6211\u4eec\u914d\u7f6e\u7684\u4e1c\u897f\uff0c\u662f\u5982\u4f55\u914d\u7f6e\u5230\u4e00\u4e2a\u4e2a\u7684\u914d\u7f6e\u7c7b\u4e2d\u7684\u3002<\/p>\n\n\n\n<p><strong>yml\u914d\u7f6e\u6587\u4ef6\u4e2d\u53ef\u4ee5\u914d\u7f6e\u90a3\u4e9b\u4e1c\u897f<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\u8981\u77e5\u9053\u8fd9\u4e2a\u95ee\u9898\u7684\u7b54\u6848\uff0c\u6211\u4eec\u5e94\u8be5\u4e60\u60efspringboot\u7684\u914d\u7f6e\u65b9\u5f0f\u3002\u5728\u4e0a\u6587\u4e2d\u6211\u4eec\u9610\u8ff0\u4e86SpringBoot\u603b\u662f\u5c06\u6240\u6709\u7684\u914d\u7f6e\u90fd\u7528JavaConfig\u7684\u5f62\u5f0f\u53bb\u5448\u73b0\u51fa\u6765\uff0c\u8fd9\u6837\u80fd\u591f\u4f7f\u4ee3\u7801\u66f4\u52a0\u4f18\u96c5\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48yml\u4e2d\u914d\u7f6e\u7684\u4e1c\u897f\uff0c\u5fc5\u7136\u662f\u8981\u548c\u8fd9\u79cd\u914d\u7f6e\u6a21\u5f0f\u53bb\u8fdb\u884c\u8054\u7cfb\u7684\uff0c\u6211\u4eec\u5728application.yml\u4e2d\u914d\u7f6e\u7684\u4e1c\u897f\uff0c\u901a\u5e38\u662f\u4e00\u4e9b\u5b58\u5728\u4e0e\u81ea\u52a8\u914d\u7f6e\u7c7b\u4e2d\u7684\u5c5e\u6027\uff0c\u90a3\u4e48\u8fd9\u4e9b\u81ea\u52a8\u914d\u7f6e\u7c7b\uff0c\u5728\u542f\u52a8\u7684\u65f6\u5019\u662f\u600e\u4e48\u627e\u5230\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u8fd8\u8bb0\u5f97\u4e0a\u6587\u7684\u63cf\u8ff0\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5f88\u660e\u786e\u5730\u77e5\u9053\uff1aspring.factories\uff01\u6ca1\u9519\uff0c\u5c31\u662f\u5b83\uff0c\u6240\u4ee5\u8fd9\u4e2a\u95ee\u9898\u6211\u4eec\u4f3c\u4e4e\u5f97\u5230\u4e86\u7b54\u6848\u2014\u2014\u53ea\u8981\u5b58\u5728\u4e0espring.factories\u4e2d\u7684\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u5728application.yml\u4e2d\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u4e0d\u5b58\u5728\u5176\u4e2d\u7684\u6211\u4eec\u5c31\u4e0d\u80fd\u914d\u7f6e\uff0c\u8fd9\u4e9b\u914d\u7f6e\u7c7b\u6211\u4eec\u662f\u53ef\u4ee5\u8fdb\u884c\u81ea\u5b9a\u4e49\u7684\uff0c\u53ea\u8981\u6211\u4eec\u5199\u4e86\u914d\u7f6e\u7c7b\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728yml\u4e2d\u914d\u7f6e\u6211\u4eec\u9700\u8981\u7684\u5c5e\u6027\u503c\uff0c\u7136\u540e\u5728\u914d\u7f6e\u7c7b\u4e2d\u76f4\u63a5\u8bfb\u53d6\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u5c06\u5176\u6620\u5c04\u5230\u914d\u7f6e\u7c7b\u7684\u5c5e\u6027\u4e0a\u3002\u90a3\u4e48\u5c31\u7275\u626f\u51fa\u6211\u4eec\u7684\u95ee\u9898\u4e86\uff1a\u914d\u7f6e\u7c7b\u662f\u5982\u4f55\u53bb\u8bfb\u53d6yml\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4fe1\u606f\u7684\u5462\uff1f<\/p>\n\n\n\n<p><strong>@ConfigurationProperties<\/strong><\/p>\n\n\n\n<p>\u8981\u660e\u767d\u8fd9\u4e2a\u95ee\u9898\u3002\u6211\u4eec\u5c31\u9996\u5148\u8981\u53bb\u4e86\u89e3\u8fd9\u4e2a\u6ce8\u89e3\u6709\u4ec0\u4e48\u4f5c\u7528\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u81ea\u5df1\u5c1d\u8bd5\u5728application.yml\u4e2d\u53bb\u5b9a\u4e49\u4e00\u4e9b\u5c5e\u6027\uff0c\u5982\u4e0b\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=\"\">object: \n  name: Object\n  blogurl: blog.objectspace.cn<\/pre>\n\n\n\n<p>\u6211\u4eec\u73b0\u5728\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e2a\u7c7b\u53bb\u8bfb\u53d6\u8fd9\u4e2a\u6587\u4ef6\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=\"\">@Component\n@ConfigurationProperties(prefix = \"object\")\npublic class TestConfig {\n    private String name;\n    private String blogUrl;\n    public String getName() {\n        return name;\n    }\n    public void setName(String name) {\n        this.name = name;\n    }\n    public String getBlogUrl() {\n        return blogUrl;\n    }\n    public void setBlogUrl(String blogUrl) {\n        this.blogUrl = blogUrl;\n    }\n}<\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u8f93\u51fa\u4e00\u4e0b\u8fd9\u4e2a\u5bf9\u8c61\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=\"\">@SpringBootTest\nclass SpringbootdemoApplicationTests {\n    @Autowired\n    TestConfig testConfig;\n    @Test\n    void contextLoads() {\n        System.out.println(testConfig.getName());\n        System.out.println(testConfig.getBlogUrl());\n    }\n\n}<\/pre>\n\n\n\n<p>\u6d4b\u8bd5\u7ed3\u679c\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-282.png\" alt=\"\" class=\"wp-image-10870\" width=\"246\" height=\"87\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-282.png 628w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-282-300x106.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-282-230x81.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-282-350x124.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-282-480x170.png 480w\" sizes=\"(max-width: 246px) 100vw, 246px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u63a7\u5236\u53f0\u4e2d\u8f93\u51fa\u4e86\u6211\u4eec\u5728yml\u4e2d\u914d\u7f6e\u7684\u5c5e\u6027\u503c\uff0c\u4f46\u662f\u8fd9\u4e9b\u503c\u6211\u4eec\u6ca1\u6709\u5728\u4efb\u4f55\u5730\u65b9\u663e\u5f0f\u5730\u5bf9\u8fd9\u4e2a\u5bf9\u8c61\u8fdb\u884c\u6ce8\u5165\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5@ConfigurationProperties\u8fd9\u4e2a\u6ce8\u89e3\uff0c\u53ef\u4ee5\u5c06yml\u6587\u4ef6\u4e2d\u5199\u597d\u7684\u503c\u6ce8\u5165\u5230\u6211\u4eec\u7c7b\u7684\u5c5e\u6027\u4e2d\u3002<\/p>\n\n\n\n<p><strong>\u660e\u767d\u4e86\u5b83\u7684\u4f5c\u7528\uff0c\u5c31\u80fd\u660e\u767d\u81ea\u52a8\u914d\u7f6e\u7c7b\u5de5\u4f5c\u7684\u539f\u7406\u4e86\u3002<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u4f9d\u65e7\u662f\u9009\u53d6SpringMVC\u7684\u81ea\u52a8\u914d\u7f6e\u7c7b\uff0c\u6211\u4eec\u6765\u770b\u770b\u5176\u4e2d\u6709\u4e9b\u4ec0\u4e48\u4e1c\u897f\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-283-1024x499.png\" alt=\"\" class=\"wp-image-10871\" width=\"419\" height=\"204\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-1024x499.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-300x146.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-768x374.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-1536x748.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-830x404.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-230x112.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-350x170.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283-480x234.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-283.png 1602w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure><\/div>\n\n\n\n<p>\u70b9\u51fb\u4efb\u610f\u4e00\u4e2a*Properties\u7c7b\u4e2d\uff0clook\u4e00\u4e0b\u5176\u4e2d\u7684\u5185\u5bb9\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-285-1024x599.png\" alt=\"\" class=\"wp-image-10873\" width=\"436\" height=\"255\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-1024x599.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-300x175.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-768x449.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-830x485.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-230x134.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-350x205.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285-480x281.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-285.png 1266w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/figure><\/div>\n\n\n\n<p>\u770b\u5230\u8fd9\u91cc\u76f8\u4fe1\u6240\u6709\u4eba\u90fd\u660e\u767d\u4e86\uff0c\u6211\u4eec\u5c31\u62ffmvc\u914d\u7f6e\u6765\u4e3e\u4f8b\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-284.png\" alt=\"\" class=\"wp-image-10872\" width=\"419\" height=\"145\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-284.png 750w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-284-300x103.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-284-230x79.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-284-350x120.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-284-480x165.png 480w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u5728yml\u4e2d\u914d\u7f6e\u7684date-format,\u5c31\u53ef\u4ee5\u901a\u8fc7@ConfigurationProperties\u6620\u5c04\u5230\u7c7b\u4e2d\u7684dateFormat\u4e2d,\u7136\u540e\u5728\u901a\u8fc7\u81ea\u52a8\u914d\u7f6e\u7c7b\uff0c\u5c06\u8fd9\u4e9b\u5c5e\u6027\u914d\u7f6e\u5230\u914d\u7f6e\u7c7b\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 Spring\u7ffb\u8bd1\u4e3a\u4e2d\u6587\u662f\u201c\u6625\u5929\u201d\uff0c\u7684\u786e\uff0c\u5728\u67d0\u6bb5\u65f6\u95f4\u5185\uff0c\u5b83\u7ed9Java\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u8fc7\u6625\u5929\uff0c\u4f46\u662f\u968f\u7740\u6211\u4eec\u9879\u76ee\u89c4 [&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\/10856"}],"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=10856"}],"version-history":[{"count":5,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10856\/revisions"}],"predecessor-version":[{"id":10878,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10856\/revisions\/10878"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}