{"id":165,"date":"2023-11-09T15:58:23","date_gmt":"2023-11-09T07:58:23","guid":{"rendered":"http:\/\/ericw.top\/?p=165"},"modified":"2023-11-09T20:47:46","modified_gmt":"2023-11-09T12:47:46","slug":"165","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=165","title":{"rendered":"Using Spring Boot"},"content":{"rendered":"<h1 id=\"toc-0\">Using Spring Boot<\/h1>\n<p><a href=\"https:\/\/springdoc.cn\/spring-boot\/using.html#using\" title=\"\u4f7f\u7528Spring Boot\u8fdb\u884c\u5f00\u53d1 (springdoc.cn)\">\u4f7f\u7528Spring Boot\u8fdb\u884c\u5f00\u53d1 (springdoc.cn)<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/11\/1699516860126-1-300x143.png\" alt=\"\" \/><\/p>\n<h2 id=\"toc-1\">\u4e00 \u6784\u5efa\u7cfb\u7edf<\/h2>\n<p>\u6784\u5efa\u7cfb\u7edf\u662f\u4e00\u4e2a\u7528\u4e8e<strong>\u7b80\u5316Spring\u5e94\u7528\u7a0b\u5e8f<\/strong>\u7684\u521d\u59cb\u5316\u5f00\u53d1\u8fc7\u7a0b\u7684\u6846\u67b6<br \/>\n\u5b83\u63d0\u4f9b\u4e86\u4e00\u5957\u7ea6\u5b9a\u548c\u9ed8\u8ba4\u914d\u7f6e\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u642d\u5efa\u5f00\u53d1Spring\u5e94\u7528\u7a0b\u5e8f<br \/>\n\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5f00\u53d1\u5de5\u5177\u548c\u6269\u5c55\uff0c\u66ff\u8eab\u5f00\u53d1\u6548\u7387\u548c\u4fbf\u6377\u6027<\/p>\n<h3 id=\"toc-2\">1.1 \u4f9d\u8d56\u7ba1\u7406<\/h3>\n<p>Spring Boot\u7684\u6bcf\u4e2a\u7248\u672c\u90fd\u63d0\u4f9b\u4e86\u6240\u652f\u6301\u7684\u4f9d\u8d56\u7684\u5217\u8868<br \/>\n<strong>\u6211\u4eec\u4e0d\u9700\u8981\u5728\u6784\u5efa\u914d\u7f6e\u4e2d\u4e3a\u8fd9\u4e9b\u4f9d\u8d56\u58f0\u660e\u7248\u672c\uff0cSpringboot\u4f1a\u4e3a\u6211\u7ba1\u7406\u8fd9\u4e9b\u4f9d\u8d56\u7ba1\u7406<\/strong><\/p>\n<blockquote>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u81ea\u5df1\u58f0\u660e\u4f9d\u8d56\u7684\u7248\u672c  \u6765\u8986\u76d6SpringBoot\u9ed8\u8ba4\u7248\u672c<\/p>\n<\/blockquote>\n<p>spring-boot-dependencies \u7684\u4f7f\u7528<\/p>\n<ol>\n<li>\u7ee7\u627fparent<br \/>\n\u5728pom.xml\u4e2d\u6dfb\u52a0<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-xml\">&lt;parent&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-dependencies&lt;\/artifactId&gt;\n    &lt;version&gt;1.5.4.RELEASE&lt;\/version&gt;\n&lt;\/parent&gt;\n<\/code><\/pre>\n<p>\u8fd9\u6837  \u5f53\u6211\u4eec\u518d\u5bfc\u5165\u9700\u8981\u7684springboot starter  \u5c31\u53ef\u4ee5\u5ffd\u7565\u7248\u672c\u53f7\u4e86<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-xml\">&lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h3 id=\"toc-3\">1.2 Maven<\/h3>\n<p>Maven\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u9879\u76ee\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u6784\u5efa\u3001\u53d1\u5e03\u548c\u7ba1\u7406Java\u9879\u76ee\u3002<br \/>\n\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7ed3\u6784\u5316\u7684\u65b9\u5f0f\u6765\u7ec4\u7ec7\u548c\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u81ea\u52a8\u5904\u7406\u7f16\u8bd1\u3001\u6d4b\u8bd5\u3001\u6253\u5305\u7b49\u4efb\u52a1\u3002<br \/>\n<a href=\"https:\/\/maven.apache.org\/\" title=\"Maven\u5b98\u65b9\u6587\u6863\">Maven\u5b98\u65b9\u6587\u6863<\/a><\/p>\n<h3 id=\"toc-4\">1.3 Starter<\/h3>\n<p>Starter\u662f\u4e00\u7cfb\u5217\u7684\u4f9d\u8d56  \u4f60\u53ef\u4ee5\u5728\u4f60\u7684\u5e94\u7528\u4e2d\u5bfc\u5165\u4ed6\u4eec<br \/>\n<strong>Starter\u542b\u4e86\u5f88\u591a\u4f60\u9700\u8981\u7684\u4f9d\u8d56\uff0c\u4ee5\u4f7f\u9879\u76ee\u5feb\u901f\u542f\u52a8\u548c\u8fd0\u884c<\/strong>\uff0c\u5e76\u62e5\u6709\u4e00\u5957\u4e00\u81f4\u7684\u3001\u53d7\u652f\u6301\u7684\u53ef\u7ba1\u7406\u7684\u8fc7\u6e21\u6027\u4f9d\u8d56\u3002<\/p>\n<hr \/>\n<h2 id=\"toc-5\">\u4e8c \u4ee3\u7801\u7ed3\u6784<\/h2>\n<h3 id=\"toc-6\">2.1 default \u5305<\/h3>\n<p>\u5f53\u4e00\u4e2a\u7c7b\u4e0d\u5305\u62ec<strong>package<\/strong>\u7684\u58f0\u660e\u65f6\uff0c\u5b83\u88ab\u8ba4\u4e3a\u662f\u5728 \u201cdefault package\u201d \u4e2d\u3002<br \/>\n\u901a\u5e38\u4e0d\u4f7f\u7528default package<br \/>\n\u5bf9\u4e8e\u4f7f\u7528\u4e86@ComponentScan, @ConfigurationPropertiesScan, @EntityScan \u6216\u8005 @SpringBootApplication   \u6ce8\u89e3\u7684Springboot\u7684\u5e94\u7528\u7a0b\u5e8f\u6765\u8bf4\uff0c\u9879\u76ee\u4e2d\u7684\u6240\u6709jar\u7684\u6240\u6709class\u90fd\u4f1a\u88ab\u626b\u63cf<\/p>\n<blockquote>\n<p>\u6211\u4eec\u4e00\u822c\u4f7f\u7528 \u57df\u540d\u53cd\u8f6c\u4f5c\u4e3a\u5305\u540d\uff08\u4f8b\u5982\uff1acom.example.project\uff09<\/p>\n<\/blockquote>\n<h3 id=\"toc-7\">2.2 \u542f\u52a8\u7c7b\u7684\u4f4d\u7f6e<\/h3>\n<p>\u6211\u4eec\u901a\u5e38\u5efa\u8bae\u5c06\u542f\u52a8\u7c7b\u653e\u5728\u6839package\u4e2d \u9ad8\u4e8e\u5176\u4ed6\u7684\u7c7b \uff0c@SpringBootApplication  \u6ce8\u89e3\u4e00\u822c\u90fd\u662f\u7528\u5728\u542f\u52a8\u7c7b\u4e0a\u7684\uff0c\u5b83\u9ed8\u8ba4\u4f1a\u626b\u63cf\u5f53\u524d\u7c7b\u4e0b\u7684\u6240\u6b32\u5b50\u5305\u3002<br \/>\n@SpringBootApplication \u9ed8\u8ba4\u53ea\u4f1a\u626b\u63cf\u52a0\u8f7d\u4f60\u9879\u76ee\u5de5\u7a0b\u4e2d\u7684\u7ec4\u4ef6\u3002<br \/>\n\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528@EnableAutoConfiguration \u548c @ComponentScan  \u4e5f\u53ef\u4ee5\u7528\u6765\u4ee3\u66ff@SpringBootApplication<\/p>\n<p>MyApplication.java \u6587\u4ef6\u58f0\u660e\u4e86main\u65b9\u6cd5 \uff0c\u4ee5\u53ca\u6807\u8bc6\u4e86\u57fa\u672c\u7684@SpringBootApplication\u6ce8\u89e3<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">@SpringBootApplication\npublic class MyApplication {\n\n    public static void main(String[] args) {\n        SpringApplication.run(MyApplication.class, args);\n    }\n\n}\n<\/code><\/pre>\n<h2 id=\"toc-8\">\u4e09 Configuration \u7c7b<\/h2>\n<p>SpringBoot\u503e\u5411\u4e8e\u901a\u8fc7Java\u4ee3\u7801\u6765\u8fdb\u884c\u914d\u7f6e\u7684\u5b9a\u4e49<br \/>\n\u4e5f\u4f1a\u6709\u4f7f\u7528XML\u6587\u4ef6\u6765\u914d\u7f6eSpringBoot<br \/>\n\u4f46\u662f\u4e00\u822c\u8fd8\u662f\u4f7f<strong>\u7528@Configuration \u7c7b<\/strong> \u6765\u8fdb\u884c\u914d\u7f6e<\/p>\n<p>\u901a\u5e38\u542f\u52a8\u7c7b\u662f\u4e3b\u8981\u7684@Configuration<\/p>\n<p>@Configuration \u6ce8\u89e3        \u7528\u4e8e\u5b9a\u4e49\u5f53\u524d\u7c7b\u4e3a\u914d\u7f6e\u7c7b<\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b \u52a0\u4e86@Configuration \u7684\u914d\u7f6e\u7c7b\u5185\u90e8\u4f1a\u6709\u4e00\u4e2a\u6216\u591a\u4e2a@Bean\u6ce8\u89e3\u7684\u65b9\u6cd5<br \/>\n@Bean  \u6ce8\u89e3    \u5de5\u5382\u65b9\u6cd5<\/p>\n<blockquote>\n<p>\u8fd9\u91cc\u5927\u5bb6\u5f88\u5bb9\u6613\u4ea7\u751f\u4e00\u4e2a\u8bef\u89e3\uff0c\u8ba4\u4e3a\u53ea\u6709\u5728\u52a0\u4e86@Configuration\u7684\u914d\u7f6e\u7c7b\u4e2d\uff0c\u4f7f\u7528@Bean\uff0c\u624d\u80fd\u5c06\u81ea\u5b9a\u4e49\u521b\u5efa\u7684\u5bf9\u8c61\u653e\u5165Spring\u5bb9\u5668\u4e2d\u3002<br \/>\n\u5176\u5b9e\u4e0d\u7136\uff0c\u5728Spring\u4e2d\uff1a\u4e07\u7269\u7686\u4e3a\u914d\u7f6e\u7c7b\u3002<br \/>\n\u5728\u4efb\u4f55\u80fd\u591f\u88abSpring\u7ba1\u7406\u7684\u7c7b(\u6bd4\u5982\u52a0\u4e86@Component\u7684\u7c7b)\u4e2d\uff0c\u5b9a\u4e49@Bean\u65b9\u6cd5\uff0c\u90fd\u80fd\u5c06\u81ea\u5b9a\u4e49\u5bf9\u8c61\u653e\u5165\u5230Spring\u5bb9\u5668<br \/>\n@Bean\u672c\u8eab\u7684\u80fd\u529b\u548c@Configuration\u65e0\u5173\u54e6\u3002<\/p>\n<\/blockquote>\n<p>@Configuration\u7ee7\u627f\u4e86@Component  \u8fd9\u610f\u5473\u7740@Configuration\u62e5\u6709@Component\u7684\u5168\u90e8\u529f\u80fd\uff0c\u8fd9\u4e5f\u6b63\u662f\u53ea\u52a0@Configuration\uff0c\u4e5f\u80fd\u88abSpring\u626b\u63cf\u5e76\u5904\u7406\u7684\u539f\u56e0\u3002<\/p>\n<h3 id=\"toc-9\">3.1 \u5bfc\u5165\u989d\u5916\u7684Configuration \u7c7b<\/h3>\n<p>\u4f60\u4e0d\u9700\u8981\u628a\u6240\u6709\u7684 @Configuration \u653e\u5728\u4e00\u4e2a\u7c7b\u4e2d\u3002<br \/>\n@Import \u6ce8\u89e3\u53ef\u4ee5\u7528\u6765\u5bfc\u5165\u989d\u5916\u7684\u914d\u7f6e\u7c7b\u3002<br \/>\n\u53e6\u5916\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 @ComponentScan \u6765\u81ea\u52a8\u626b\u63cf\u52a0\u8f7d\u6240\u6709Spring\u7ec4\u4ef6<\/p>\n<h3 id=\"toc-10\">3.2 \u5bfc\u5165XML Configuration<\/h3>\n<p>\u5982\u679c\u4f60\u786e\u5b9e\u9700\u8981\u4f7f\u7528\u57fa\u4e8eXML\u7684\u914d\u7f6e<br \/>\n\u5efa\u8bae\u4ecd\u7136\u4ece@Configuration \u7c7b\u5f00\u59cb<br \/>\n\u7136\u540e\u901a\u8fc7@ImportResource \u6ce8\u89e3\u6765\u52a0\u8f7dXML\u914d\u7f6e\u6587\u4ef6<\/p>\n<h3 id=\"toc-11\">3.3 @Bean<\/h3>\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/99870991\" title=\"\u8bb2\u89e3Spring\u7684@bean\u6ce8\u89e3\">\u8bb2\u89e3Spring\u7684@bean\u6ce8\u89e3<\/a><br \/>\n<strong>@Bean\u6ce8\u89e3 \u5c31\u662f\u751f\u6210\u4e00\u4e2aBean \uff0c\u5e76\u5c06\u4ed6\u4ea4\u7ed9Spring\u5bb9\u5668\u53bb\u7ba1\u7406<\/strong><br \/>\n@Bean\u6ce8\u89e3\u662f\u7528\u4e8e\u58f0\u660e\u4e00\u4e2aBean\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u7528\u5728@Configuration\u7c7b\u4e2d\u3002<br \/>\n<strong>\u5f53Spring\u5bb9\u5668\u542f\u52a8\u65f6\uff0c\u4f1a\u626b\u63cf\u6240\u6709\u5e26\u6709@Bean\u6ce8\u89e3\u7684\u65b9\u6cd5\uff0c\u5e76\u5c06\u5176\u8fd4\u56de\u503c\u4f5c\u4e3a\u4e00\u4e2aBean\u6ce8\u518c\u5230\u5bb9\u5668\u4e2d\u3002<\/strong><br \/>\n@Bean\u7684\u4f5c\u7528\u662f\uff1a<br \/>\n1.<strong>\u521b\u5efaBean\u5b9e\u4f8b<\/strong>\uff1a\u4f7f\u7528@Bean\u6ce8\u89e3\u6807\u8bb0\u7684\u65b9\u6cd5\u5c06\u88ab\u8c03\u7528\uff0c\u8fd4\u56de\u7684\u5bf9\u8c61\u5c06\u88ab\u6ce8\u518c\u4e3a\u4e00\u4e2aBean\u5b9e\u4f8b\u3002<br \/>\n2.<strong>\u81ea\u5b9a\u4e49Bean\u7684\u521b\u5efa\u903b\u8f91<\/strong>\uff1a\u901a\u8fc7@Bean\u6ce8\u89e3\u53ef\u4ee5\u81ea\u5b9a\u4e49Bean\u7684\u521b\u5efa\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u624b\u52a8\u5b9e\u4f8b\u5316\u548c\u521d\u59cb\u5316Bean\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u6761\u4ef6\u8fdb\u884c\u6761\u4ef6\u5316\u7684Bean\u521b\u5efa\u3002<br \/>\n3.<strong>\u6ce8\u5165\u5176\u4ed6Bean<\/strong>\uff1a@Bean\u65b9\u6cd5\u53ef\u4ee5\u63a5\u53d7\u5176\u4ed6Bean\u4f5c\u4e3a\u53c2\u6570\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u5176\u4ed6Bean\u7684\u5f15\u7528\u548c\u4f9d\u8d56\u6ce8\u5165\u3002<br \/>\n4.<strong>\u914d\u7f6eBean\u5c5e\u6027<\/strong>\uff1a\u901a\u8fc7\u65b9\u6cd5\u53c2\u6570\u6216\u65b9\u6cd5\u4f53\u5185\u90e8\u4ee3\u7801\uff0c\u53ef\u4ee5\u914d\u7f6eBean\u7684\u5c5e\u6027\u548c\u4f9d\u8d56\u5173\u7cfb\u3002<br \/>\n5.<strong>\u63d0\u4f9b\u5355\u4f8b\u6a21\u5f0f\u7684Bean<\/strong>\uff1a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7@Bean\u6ce8\u89e3\u58f0\u660e\u7684Bean\u90fd\u662f\u5355\u4f8b\u6a21\u5f0f\u7684\uff0c\u5373\u6bcf\u6b21\u83b7\u53d6\u8be5Bean\u65f6\u90fd\u4f1a\u5f97\u5230\u540c\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<p><strong>@Bean\u6ce8\u89e3\u7684\u4f5c\u7528\u662f\u5728@Configuration\u7c7b\u4e2d\u58f0\u660e\u4e00\u4e2aBean\u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u521b\u5efa\u3001\u5b9a\u5236\u548c\u6ce8\u518cBean\u5b9e\u4f8b\u5230Spring\u5bb9\u5668\u4e2d\u3002<\/strong><\/p>\n<h2 id=\"toc-12\">\u56db \u81ea\u52a8\u88c5\u914d\uff08\u914d\u7f6e\uff09<\/h2>\n<p>Spring Boot\u7684\u81ea\u52a8\u88c5\u914d\u673a\u5236\u4f1a\u8bd5\u56fe\u6839\u636e\u4f60\u6240\u6dfb\u52a0\u7684\u4f9d\u8d56\u6765\u81ea\u52a8\u914d\u7f6e\u4f60\u7684Spring\u5e94\u7528\u7a0b\u5e8f\u3002<br \/>\n\u4f60\u9700\u8981\u5c06 @EnableAutoConfiguration \u6216 @SpringBootApplication \u6ce8\u89e3\u6dfb\u52a0\u5230\u4f60\u7684 @Configuration \u7c7b\u4e2d\uff0c\u4ece\u800c\u5f00\u542f\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u3002<\/p>\n<blockquote>\n<p>\u4f60\u5e94\u8be5\u53ea\u6dfb\u52a0\u4e00\u4e2a @SpringBootApplication \u6216 @EnableAutoConfiguration \u6ce8\u89e3\u3002 \u5efa\u8bae\u6dfb\u52a0\u5230\u4e3b\u8981\u7684 @Configuration \u7c7b\u4e0a\u3002<\/p>\n<\/blockquote>\n<h3 id=\"toc-13\">4.1 \u9010\u6b65\u53d6\u4ee3\u81ea\u52a8\u914d\u7f6e<\/h3>\n<p><strong>\u81ea\u52a8\u914d\u7f6e\u662f\u975e\u4fb5\u5165\u6027\u7684  <\/strong><br \/>\n\u5728\u4efb\u4f55\u65f6\u5019\uff0c\u4f60\u90fd\u53ef\u4ee5\u5f00\u59cb\u5b9a\u4e49\u4f60\u81ea\u5df1\u7684\u914d\u7f6e\u6765\u53d6\u4ee3\u81ea\u52a8\u88c5\u914d\u7684\u7279\u5b9a\u90e8\u5206<\/p>\n<blockquote>\n<p>\u5982\u679c\u4f60\u60f3\u77e5\u9053\u5728\u5e94\u7528\u4e2d\u4f7f\u7528\u4e86\u54ea\u4e9b\u81ea\u52a8\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u5728\u542f\u52a8\u547d\u4ee4\u540e\u6dfb\u52a0 --debug \u53c2\u6570\u3002 \u8fd9\u4e2a\u53c2\u6570\u4f1a\u4e3a\u6838\u5fc3\u7684logger\u5f00\u542fdebug\u7ea7\u522b\u7684\u65e5\u5fd7\uff0c\u4f1a\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u81ea\u52a8\u88c5\u914d\u9879\u76ee\u4ee5\u53ca\u89e6\u53d1\u81ea\u52a8\u88c5\u914d\u7684\u6761\u4ef6\u3002<\/p>\n<\/blockquote>\n<h3 id=\"toc-14\">4.2 \u7981\u7528\u6307\u5b9a\u7684\u81ea\u52a8\u88c5\u914d\u7c7b<\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u7981\u7528\u6389\u9879\u76ee\u4e2d\u67d0\u4e9b\u81ea\u52a8\u88c5\u914d\u7c7b\uff0c\u4f60\u53ef\u4ee5\u5728@SpringBootApplication\u6ce8\u89e3\u7684exclude\u5c5e\u6027\u4e2d\u6307\u5b9a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })\npublic class MyApplication {\n\n}<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u6ce8\u89e3 + \u914d\u7f6e\u7684\u65b9\u5f0f\u6765\u7981\u7528\u81ea\u52a8\u88c5\u914d\u7c7b\u3002<\/p>\n<h2 id=\"toc-15\">\u4e94 Spring Bean \u548c\u4f9d\u8d56\u6ce8\u5165<\/h2>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6807\u51c6\u7684Spring\u6280\u672f \u5b9a\u4e49Bean\u548c\u4f9d\u8d56\u6ce8\u5165\u5173\u7cfb\u3002<br \/>\n\u63a8\u8350\u4f7f\u7528\u6784\u9020\u51fd\u6570\u6ce8\u5165\uff0c\u5e76\u4f7f\u7528@ComponentScan\u6ce8\u89e3\u6765\u626b\u63cfBean<\/p>\n<p>\u4f60\u53ef\u4ee5\u5728\u542f\u52a8\u7c7b\u4e2d\u6dfb\u52a0@ComponentScan\u6ce8\u89e3\uff0c\u4e5f\u4e0d\u9700\u8981\u5b9a\u4e49\u5b83\u7684\u53c2\u6570<br \/>\n\u8fd9\u6837\u4f60\u7684\u6240\u6709\u5e94\u7528\u7ec4\u4ef6\uff08@Component\u3001@Service\u3001@Repository\u3001@Controler\u548c\u5176\u4ed6\uff09\u90fd\u4f1a\u81ea\u52a8\u6ce8\u518c\u4e3aSpring Bean<\/p>\n<blockquote>\n<p><strong>@SpringBootApplication\u6ce8\u89e3\u4e2d\u5305\u542b\u4e86@ComponentScan<\/strong><\/p>\n<\/blockquote>\n<p>\u5982\u679c\u4e00\u4e2aBean\u6709\u591a\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u4f60\u9700\u8981\u7528 @Autowired \u6ce8\u89e3\u6765\u544a\u8bc9Spring\u8be5\u7528\u54ea\u4e2a\u6784\u9020\u51fd\u6570\u8fdb\u884c\u6ce8\u5165\u3002<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">@Service\npublic class MyAccountService implements AccountService {\n\n    private final RiskAssessor riskAssessor;\n\n    private final PrintStream out;\n\n    @Autowired\n    public MyAccountService(RiskAssessor riskAssessor) {\n        this.riskAssessor = riskAssessor;\n        this.out = System.out;\n    }\n\n    public MyAccountService(RiskAssessor riskAssessor, PrintStream out) {\n        this.riskAssessor = riskAssessor;\n        this.out = out;\n    }\n\n    \/\/ ...\n\n}<\/code><\/pre>\n<p><strong>@Autowired\u8be6\u89e3<\/strong><br \/>\n@Autowired\u53ef\u4ee5\u6807\u6ce8\u5728\u5c5e\u6027\u4e0a\u3001\u65b9\u6cd5\u4e0a\u548c\u6784\u9020\u5668\u4e0a\uff0c\u6765\u5b8c\u6210\u81ea\u52a8\u88c5\u914d\u3002<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">@Autowired\u539f\u7406\uff1a\n        \u4e3e\u4f8b\uff1a@Autowired\n              private BookService bookService;\n        1\uff09\u3001\u5148\u6309\u7167\u7c7b\u578b\u53bb\u5bb9\u5668\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u7ec4\u4ef6\uff1b\n            bookService = ioc.getBean(BookService.class)\n            \u2460\u3001\u627e\u5230\u4e00\u4e2a\uff1a\u627e\u5230\u5c31\u8d4b\u503c\n            \u2461\u3001\u6ca1\u627e\u5230\u5c31\u62a5\u5f02\u5e38\n            \u2462\u3001\u6309\u7167\u7c7b\u578b\u53ef\u4ee5\u627e\u5230\u591a\u4e2a\uff1f\u627e\u5230\u591a\u4e2a\u5982\u4f55\u88c5\u914d\u4e0a\uff1f\n                a\u3001\u7c7b\u578b\u4e00\u6837\u5c31\u6309\u7167\u53d8\u91cf\u540d\u4e3aID\u7ee7\u7eed\u5339\u914d\n                  \u2160\u3001\u5339\u914d\u4e0a\u5c31\u88c5\u914d\n                  \u2161\u3001\u6ca1\u6709\u5339\u914d\uff1f\u62a5\u9519\n                        \u539f\u56e0\uff1a\u56e0\u4e3a\u6211\u4eec\u6309\u7167\u53d8\u91cf\u540d\u4f5c\u4e3aid\u7ee7\u7eed\u5339\u914d\u7684\n                        \u4f7f\u7528@Qualifier\u6307\u5b9a\u4e00\u4e2a\u65b0\u7684id\n                            \u627e\u5230\u5c31\u5339\u914d<\/code><\/pre>\n<h2 id=\"toc-16\">\u516d \u4f7f\u7528@SpringBootApplication\u6ce8\u89e3<\/h2>\n<p><strong>@SpringBootApplication\u7684\u529f\u80fd\uff1a<\/strong><br \/>\n\u25cf@EnableAutoConfiguration\uff1a\u542f\u7528Spring Boot\u7684<strong>\u81ea\u52a8\u914d\u7f6e\u673a\u5236<\/strong>\u3002<br \/>\n\u25cf@ComponentScan\uff1a\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6240\u5728\u7684\u5305\u542f\u7528 <strong>@Component \u626b\u63cf<\/strong>\u3002<br \/>\n\u25cf@SpringBootConfiguration\uff1a\u5141\u8bb8\u5728Context\u4e2d\u6ce8\u518c\u989d\u5916\u7684Bean\u6216<strong>\u5bfc\u5165\u989d\u5916\u7684\u914d\u7f6e\u7c7b<\/strong>\u3002\u8fd9\u662fSpring\u6807\u51c6\u7684 @Configuration \u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u6709\u52a9\u4e8e\u5728\u4f60\u7684\u96c6\u6210\u6d4b\u8bd5\u4e2d\u68c0\u6d4b\u914d\u7f6e\u3002<\/p>\n<h2 id=\"toc-17\">\u4e03 \u8fd0\u884c\u4f60\u7684\u5e94\u7528<\/h2>\n<p><strong>\u5e94\u7528\u6253\u5305\u6210\u53ef\u6267\u884c\u7684jar\uff0c\u4f7f\u7528\u5d4c\u5165\u5f0fHTTP\u670d\u52a1\u5668\u6700\u5927\u4f18\u52bf\uff0c\u5c31\u53ef\u4ee5\u50cf\u5176\u4ed6\u7a0b\u5e8f\u4e00\u6837\u8fd0\u884c<\/strong><\/p>\n<h3 id=\"toc-18\">7.1 \u8fd0\u884c\u6253\u5305\u540e\u7684\u5e94\u7528<\/h3>\n<p>\u4f7f\u7528Spring Boot\u7684Maven\u6216Gradle\u63d2\u4ef6\u6765\u521b\u5efa\u53ef\u6267\u884cjar\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 java -jar \u6765\u8fd0\u884c\u4f60\u7684\u6253\u5305\u540e\u5e94\u7528\u7a0b\u5e8f<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">$ java -jar target\/myapplication-0.0.1-SNAPSHOT.jar\n<\/code><\/pre>\n<p>\u6253\u5305\u540e\u7684jar\u7a0b\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u53c2\u6570\u5f00\u542f\u8fdc\u7a0b\u8c03\u8bd5\u670d\u52a1<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \\\n       -jar target\/myapplication-0.0.1-SNAPSHOT.jar<\/code><\/pre>\n<h3 id=\"toc-19\">7.2 \u4f7f\u7528Maven \u63d2\u4ef6<\/h3>\n<p>Spring Boot Maven \u63d2\u4ef6\u5305\u62ec\u4e00\u4e2a run \u76ee\u6807\uff08goal\uff09\uff0c\u53ef\u7528\u4e8e\u5feb\u901f\u7f16\u8bd1\u548c\u8fd0\u884c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<br \/>\n$ mvn spring-boot:run<\/p>\n<h3 id=\"toc-20\">7.3 \u70ed\u90e8\u7f72<\/h3>\n<p>Spring Boot\u5e94\u7528\u7a0b\u5e8f\u662f\u666e\u901a\u7684Java\u5e94\u7528\u7a0b\u5e8f\uff0cJVM\u7684\u70ed\u66ff\u6362\u529f\u80fd\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002<\/p>\n<h2 id=\"toc-21\">\u516b \u5f00\u53d1\u8005\u5de5\u5177\uff08Developer Tools\uff09<\/h2>\n<p>Spring Boot \u63d0\u4f9b\u4e86\u4e00\u5957\u989d\u5916\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u8ba9\u4f60\u66f4\u52a0\u6109\u5feb\u7684\u5f00\u53d1\u5e94\u7528\u3002<br \/>\nspring-boot-devtools \u6a21\u5757\u53ef\u4ee5\u5305\u542b\u5728\u4efb\u4f55\u9879\u76ee\u4e2d\uff0c\u4ee5\u5728\u5f00\u53d1\u671f\u95f4\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u7684\u7279\u6027\u3002<br \/>\n<strong>Maven:<\/strong><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-devtools&lt;\/artifactId&gt;\n        &lt;optional&gt;true&lt;\/optional&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n<h3 id=\"toc-22\">8.1 \u5c5e\u6027\u7684\u9ed8\u8ba4\u503c<\/h3>\n<p>SpringBoot\u652f\u6301\u7684\u4e00\u4e9b\u5e93\u4e2d  \u4f1a\u4f7f\u7528\u7f13\u5b58\u6765\u63d0\u9ad8\u6027\u80fd\u3002<br \/>\n\u867d\u7136\u7f13\u5b58\u5728\u751f\u4ea7\u8005\u975e\u5e38\u6709\u6548  \u4f46\u662f\u5728\u5f00\u53d1\u4e2d\u80af\u4f1a\u8d77\u5230\u53cd\u4f5c\u7528  spring-boot-devtools\u9ed8\u8ba4\u7981\u7528\u4e86\u7f13\u5b58\u9009\u9879<br \/>\n\u7f13\u5b58\u9009\u9879\u901a\u5e38\u662f\u901a\u8fc7application.properties\u6587\u4ef6\u7684\u5c5e\u6027\u6765\u914d\u7f6e\u7684<br \/>\nspring-boot-devtools\u4f1a\u5728\u5f00\u53d1\u573a\u666f\u4e0b\u5408\u7406\u8bbe\u7f6e\u8fd9\u4e9b\u5c5e\u6027<\/p>\n<h3 id=\"toc-23\">8.3 \u81ea\u52a8\u91cd\u542f<\/h3>\n<p>\u4f7f\u7528spring-boot-devtools \u7684\u5e94\u7528\u7a0b\u5e8f\u4f1a\u5728classpath\u4e0a\u7684\u6587\u4ef6\u53d1\u751f\u53d8\u5316\u65f6\u81ea\u52a8\u91cd\u542f<br \/>\n<strong>\u89e6\u53d1\u91cd\u542f\uff1a<\/strong><br \/>\n\u7531\u4e8eDevTools\u76d1\u63a7classpath\u8d44\u6e90\uff0c\u89e6\u53d1\u91cd\u542f\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u66f4\u65b0classpath\u3002<br \/>\n\u65e0\u8bba\u4f60\u4f7f\u7528\u7684\u662fIDE\u8fd8\u662f\u6784\u5efa\u63d2\u4ef6\uff0c\u88ab\u4fee\u6539\u7684\u6587\u4ef6\u90fd\u5fc5\u987b\u88ab\u91cd\u65b0\u7f16\u8bd1\u4ee5\u89e6\u53d1\u91cd\u542f\u3002<br \/>\n\u25cf\u5728IntelliJ IDEA\u4e2d\uff0c\u6784\u5efa\u9879\u76ee\uff08 Build +\u2192+ Build Project \uff09\u6709\u540c\u6837\u7684\u6548\u679c\u3002<br \/>\n\u25cf\u5982\u679c\u4f7f\u7528\u6784\u5efa\u63d2\u4ef6\uff0c\u8fd0\u884cMaven\u7684 mvn compile \u6216Gradle\u7684 gradle build \u4f1a\u89e6\u53d1\u91cd\u542f\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7528Maven\u6216Gradle\u7684\u6784\u5efa\u63d2\u4ef6\u91cd\u542f\uff0c\u4f60\u5fc5\u987b\u5c06 forking \u8bbe\u7f6e\u4e3a enabled\u3002 \u5982\u679c\u4f60\u7981\u7528 forking\uff0cdevtools\u4f7f\u7528\u7684\u201c\u5e94\u7528\u9694\u79bb\u7c7b\u52a0\u8f7d\u5668\uff08isolated application classloader\uff09\u201d\u5c06\u4e0d\u4f1a\u88ab\u521b\u5efa\uff0c\u91cd\u542f\u529f\u80fd\u5c06\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>DevTools\u4f9d\u9760\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u7684\u5173\u673ahook\u6765\u5728\u91cd\u542f\u671f\u95f4\u5173\u95ed\u5b83\u3002 \u5982\u679c\u4f60\u7981\u7528\u4e86\u5173\u673a\u94a9\u5b50\uff08 SpringApplication.setRegisterShutdownHook(false) \uff09\uff0c\u5b83\u5c31\u4e0d\u80fd\u6b63\u786e\u5de5\u4f5c\u3002<\/p>\n<p>DevTools\u9700\u8981\u5b9a\u5236 ApplicationContext \u6240\u4f7f\u7528\u7684 ResourceLoader\u3002 \u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4e00\u4e2a\uff0c\u5b83\u5c06\u88ab\u201c\u5305\u88c5\u201d\uff08\u88c5\u9970\u8005\u8bbe\u8ba1\u6a21\u5f0f\uff09\u8d77\u6765\u3002 \u4e0d\u652f\u6301\u76f4\u63a5\u8986\u76d6 ApplicationContext \u4e0a\u7684 getResource \u65b9\u6cd5\u3002<\/p>\n<h4 id=\"toc-24\">8.3.1 \u8bb0\u5f55\u6761\u4ef6\u8bc4\u4f30\u53d8\u5316<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u5e94\u7528\u91cd\u65b0\u542f\u52a8\u65f6\uff0c\u90fd\u4f1a\u8bb0\u5f55\u4e00\u4efd\u73b0\u5b9e\u6761\u4ef6\u7684\u8bc4\u4f30\u62a5\u544a<br \/>\n\u8be5\u62a5\u544a\u663e\u793a\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u81ea\u52a8\u914d\u7f6e\u7684\u53d8\u5316<br \/>\n\u7981\u7528\u62a5\u544a\u8bb0\u5f55\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring.devtools.restart.log-condition-evaluation-delta=false<\/code><\/pre>\n<pre><code class=\"prettyprint\"  class=\"language-java\">\nspring:\n  devtools:\n    restart:\n      log-condition-evaluation-delta: false<\/code><\/pre>\n<h4 id=\"toc-25\">8.3.2 \u6392\u9664\u8d44\u6e90<\/h4>\n<p>\u67d0\u4e9b\u8d44\u6e90\u5728\u88ab\u6539\u53d8\u65f6\u4e0d\u4e00\u5b9a\u9700\u8981\u89e6\u53d1\u91cd\u542f\u3002<br \/>\n\u53ef\u4ee5\u8fd9\u6837\u8bbe\u7f6e\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring.devtools.restart.exclude=static\/**,public\/**<\/code><\/pre>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring:\n  devtools:\n    restart:\n      exclude: &quot;static\/**,public\/**&quot;<\/code><\/pre>\n<h4 id=\"toc-26\">8.3.3 \u76d1\u63a7\u989d\u5916\u7684\u8def\u5f84<\/h4>\n<p>\u5f53\u4f60\u5bf9\u4e0d\u5728classpath\u4e0a\u7684\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\u65f6\uff0c\u4f60\u53ef\u80fd\u5e0c\u671b\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u88ab\u91cd\u65b0\u542f\u52a8\u6216\u91cd\u65b0\u52a0\u8f7d\u3002<\/p>\n<h4 id=\"toc-27\">8.3.4 \u7981\u6b62\u91cd\u542f<\/h4>\n<p>\u5982\u679c\u4f60\u4e0d\u60f3\u4f7f\u7528\u91cd\u542f\u529f\u80fd\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 spring.devtools.restart.enabled \u5c5e\u6027\u6765\u7981\u7528\u5b83\u3002<br \/>\n<strong>\u7981\u6b62\u91cd\u542f\uff1a<\/strong><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class MyApplication {\n\n    public static void main(String[] args) {\n        System.setProperty(&quot;spring.devtools.restart.enabled&quot;, &quot;false&quot;);\n        SpringApplication.run(MyApplication.class, args);\n    }\n\n}<\/code><\/pre>\n<h4 id=\"toc-28\">8.3.5 \u4f7f\u7528 trigger file<\/h4>\n<p>\u5982\u679c\u4f60\u60f3\u5728\u7279\u5b9a\u65f6\u95f4\u89e6\u53d1\u91cd\u542f\uff0c\u53ef\u4ee5\u4f7f\u7528trigger file\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring.devtools.restart.trigger-file=.reloadtrigger<\/code><\/pre>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring:\n  devtools:\n    restart:\n      trigger-file: &quot;.reloadtrigger&quot;<\/code><\/pre>\n<p>\u8fd9\u6837\u8bbe\u7f6e\u53ea\u6709\u5f53 src\/main\/resources\/.reloadtrigger \u88ab\u66f4\u65b0\u65f6\u624d\u4f1a\u91cd\u65b0\u542f\u52a8\u3002<\/p>\n<h4 id=\"toc-29\">8.3.6 \u81ea\u5b9a\u4e49\u91cd\u542f\u7c7b\u52a0\u8f7d\u5668<\/h4>\n<p>\u91cd\u542f\u529f\u80fd\u662f\u901a\u8fc7\u4f7f\u7528\u4e24\u4e2aclassloader\u5b9e\u73b0\u7684\uff0c\u5982\u679c\u8fd9\u5bfc\u81f4\u4e86\u5176\u4ed6\u7684\u95ee\u9898\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u81ea\u5b9a\u4e49\u7c7b\u52a0\u8f7d\u5668\u3002<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f60\u7684IDE\u4e2d\u4efb\u4f55\u6253\u5f00\u7684\u9879\u76ee\u90fd\u662f\u7528 \u201crestart\u201d \u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u7684\uff0c\u800c\u4efb\u4f55\u5e38\u89c4\u7684 .jar \u6587\u4ef6\u90fd\u662f\u7528 \u201cbase\u201d \u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u3002 \u5982\u679c\u4f60\u4f7f\u7528 mvn spring-boot:run \u6216 gradle bootRun \u4e5f\u662f\u4e00\u6837\uff1a\u5305\u542b\u4e86 @SpringBootApplication \u7684\u9879\u76ee\u7528 \u201crestart\u201d \u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\uff0c\u5176\u4ed6\u90fd\u7528 \u201cbase\u201d \u7c7b\u52a0\u8f7d\u5668\u3002<\/p>\n<h4 id=\"toc-30\">8.3.7 \u5df2\u77e5\u7684\u9650\u5236<\/h4>\n<p>\u5982\u679c\u4f60\u662f\u8981\u6807\u51c6\u7684ObjectInputStream\u6765\u53cd\u5e8f\u5217\u5316\u5bf9\u8c61\uff0c\u90a3\u4e48\u91cd\u542f\u529f\u80fd\u7684\u6548\u679c\u5e76\u4e0d\u597d<\/p>\n<h3 id=\"toc-31\">8.4 LiveReload<\/h3>\n<p>spring-boot-devtools \u6a21\u5757\u5305\u62ec\u4e00\u4e2a\u5185\u5d4c\u7684LiveReload\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u7528\u6765\u5728\u8d44\u6e90\u53d1\u751f\u53d8\u5316\u65f6\u89e6\u53d1\u6d4f\u89c8\u5668\u5237\u65b0\u3002<br \/>\n\u5982\u679c\u4f60\u4e0d\u60f3\u5728\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u542f\u52a8LiveReload\u670d\u52a1\u5668\uff0c\u4f60\u53ef\u4ee5\u5c06 spring.devtools.livereload.enabled \u5c5e\u6027\u8bbe\u7f6e\u4e3a false \u3002<\/p>\n<h3 id=\"toc-32\">8.5 \u5168\u5c40\u8bbe\u7f6e<\/h3>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728 $HOME\/.config\/spring-boot \u76ee\u5f55\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u4efb\u4f55\u6587\u4ef6\u6765\u914d\u7f6e\u5168\u5c40\u7684devtools\u8bbe\u7f6e\u3002<br \/>\n1.spring-boot-devtools.properties<br \/>\n2.spring-boot-devtools.yaml<br \/>\n3.spring-boot-devtools.yml<br \/>\n\u8fd9\u4e9b\u6587\u4ef6\u7684\u5c5e\u6027\u4f1a\u5f71\u54cd\u5230\u6211\u7684\u8bbe\u5907\u4e0a\u7684\u6240\u6709SpringBoot\u5e94\u7528\u7a0b\u5e8f<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c$HOME \u662f\u7528\u6237\u7684\u4e3b\u76ee\u5f55\u3002 \u8981\u81ea\u5b9a\u4e49\u8fd9\u4e2a\u4f4d\u7f6e\uff0c\u8bf7\u8bbe\u7f6e SPRING_DEVTOOLS_HOME \u73af\u5883\u53d8\u91cf\u6216 spring.devtools.home \u7cfb\u7edf\u5c5e\u6027\u3002<\/p>\n<h4 id=\"toc-33\">8.5.1 \u914d\u7f6e\u6587\u4ef6\u7cfb\u7edf\u7684\u76d1\u63a7<\/h4>\n<p>FileSystemWatcher \u7684\u5de5\u4f5c\u65b9\u5f0f\u662f\u4ee5\u4e00\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u8f6e\u8be2\u7c7b\u7684\u53d8\u5316\uff0c\u7136\u540e\u7b49\u5f85\u4e00\u4e2a\u9884\u5b9a\u4e49\u7684\u5b89\u9759\u671f\uff0c\u4ee5\u786e\u4fdd\u4e0d\u518d\u6709\u53d8\u5316\u3002<br \/>\n\u6709\u65f6devtools\u91cd\u65b0\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u67d0\u4e9b\u53d8\u5316\u5e76\u6ca1\u6709\u53cd\u6620\u51fa\u6765\uff08\u6ca1\u6709\u7acb\u5373\u751f\u6548\uff09<br \/>\n\u53ef\u4ee5\u5c1d\u8bd5\u589e\u52a0 <code class=\"prettyprint\" >spring.devtools.restart.poll-interval<\/code> \u548c <code class=\"prettyprint\" >spring.devtools.restart.quiet-period<\/code> \u53c2\u6570\u5230\u9002\u5408\u4f60\u5f00\u53d1\u73af\u5883\u7684\u503c\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring.devtools.restart.poll-interval=2s\nspring.devtools.restart.quiet-period=1s<\/code><\/pre>\n<pre><code class=\"prettyprint\"  class=\"language-java\">spring:\n  devtools:\n    restart:\n      poll-interval: &quot;2s&quot;\n      quiet-period: &quot;1s&quot;<\/code><\/pre>\n<p>\u8fd9\u6837\u8bbe\u7f6e\u540e\u53d7\u76d1\u63a7\u7684classpath\u76ee\u5f55\u73b0\u5728\u6bcf2\u79d2\u8f6e\u8be2\u4e00\u6b21\u53d8\u5316\uff0c\u5e76\u4fdd\u63011\u79d2\u7684\u5b89\u9759\u671f\u4ee5\u786e\u4fdd\u6ca1\u6709\u989d\u5916\u7684\u7c7b\u53d8\u5316\u3002<\/p>\n<h2 id=\"toc-34\">\u4e5d \u6253\u5305\u5e94\u7528\uff0c\u90e8\u7f72\u548c\u751f\u4ea7\u73af\u5883<\/h2>\n<p>\u53ef\u6267\u884cjar\u53ef\u4ee5\u7528\u4e8e\u751f\u4ea7\u73af\u5883\uff0c\u7531\u4e8e\u5b83\u4eec\u662f\u72ec\u7acb\u7684\uff0c\u975e\u5e38\u9002\u5408\u90e8\u7f72\u5230\u4e91\u670d\u52a1\u4e2d\u3002<\/p>\n<p>Spring Boot \u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u72ec\u7acb\u7684\u3001\u57fa\u4e8e Spring \u7684\u751f\u4ea7\u7ea7\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\u3002\u5b83\u901a\u8fc7\u63d0\u4f9b\u5f00\u7bb1\u5373\u7528\u7684\u914d\u7f6e\u548c\u7ea6\u5b9a\u6765\u7b80\u5316\u5e94\u7528\u7a0b\u5e8f\u7684\u6784\u5efa\u548c\u90e8\u7f72\u8fc7\u7a0b\uff0c\u8ba9\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u66f4\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\u7684\u5b9e\u73b0\u3002<\/p>\n<ol>\n<li>\n<p>\u6253\u5305\uff1a<strong>\u4f7f\u7528 Maven \u6216 Gradle \u8fd9\u6837\u7684\u6784\u5efa\u5de5\u5177\u53ef\u4ee5\u5c06 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u7684 JAR \u6587\u4ef6\u6216 WAR \u6587\u4ef6\u3002<\/strong>\u8fd9\u4e9b\u6587\u4ef6\u5305\u542b\u4e86\u5e94\u7528\u7a0b\u5e8f\u53ca\u5176\u4f9d\u8d56\u9879\uff0c\u5e76\u4e14\u53ef\u4ee5<strong>\u76f4\u63a5\u5728\u76ee\u6807\u73af\u5883\u4e2d\u8fd0\u884c\u3002<\/strong><\/p>\n<\/li>\n<li>\n<p>\u90e8\u7f72\uff1a\u90e8\u7f72 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u65f6\u6709\u51e0\u79cd\u9009\u62e9\u3002\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f<strong>\u5c06\u6253\u5305\u597d\u7684 JAR \u6587\u4ef6\u76f4\u63a5\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u5e76\u8fd0\u884c<\/strong>\u3002\u53e6\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5c06 WAR \u6587\u4ef6\u90e8\u7f72\u5230\u652f\u6301 Java Servlet \u5bb9\u5668\uff08\u5982 Tomcat\u3001Jetty\uff09\u7684\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>\u751f\u4ea7\u73af\u5883\u914d\u7f6e\uff1a\u4e3a\u4e86\u4f7f Spring Boot \u5e94\u7528\u7a0b\u5e8f\u5728<strong>\u751f\u4ea7\u73af\u5883\u4e2d\u8fd0\u884c\u5f97\u66f4\u53ef\u9760\u548c\u9ad8\u6548\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u989d\u5916\u7684\u914d\u7f6e<\/strong>\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u3001\u65e5\u5fd7\u8bb0\u5f55\u3001\u7f13\u5b58\u7b56\u7565\u7b49\u3002Spring Boot \u63d0\u4f9b\u4e86\u4f17\u591a\u7684\u914d\u7f6e\u9009\u9879\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\uff08\u5982 application.properties \u6216 application.yml\uff09\u6216\u7f16\u7a0b\u65b9\u5f0f\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u73af\u5883\u53d8\u91cf\u548c\u914d\u7f6e\u5c5e\u6027\uff1aSpring Boot \u5141\u8bb8\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u6216\u914d\u7f6e\u5c5e\u6027\u6765\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7\u5c06\u914d\u7f6e\u4fe1\u606f\u5916\u90e8\u5316\uff0c\u53ef\u4ee5\u4f7f\u5e94\u7528\u7a0b\u5e8f\u66f4\u5177\u53ef\u79fb\u690d\u6027\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u76d1\u63a7\u548c\u7ba1\u7406\uff1aSpring Boot \u63d0\u4f9b\u4e86\u4e00\u4e9b\u7528\u4e8e\u76d1\u63a7\u548c\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f\u7684\u529f\u80fd\u3002\u4f8b\u5982\uff0cActuator \u6a21\u5757\u63d0\u4f9b\u4e86\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4fe1\u606f\u3001\u5065\u5eb7\u72b6\u6001\u3001\u5ea6\u91cf\u6307\u6807\u7b49\u7684\u66b4\u9732\u548c\u76d1\u63a7\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u5168\u6027\uff1a\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u5b89\u5168\u6027\u662f\u4e00\u4e2a\u91cd\u8981\u95ee\u9898\u3002Spring Security \u662f Spring \u751f\u6001\u7cfb\u7edf\u4e2d\u8d1f\u8d23\u5904\u7406\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u7684\u6a21\u5757\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u4fdd\u62a4\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u786e\u4fdd\u53ea\u6709\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u7684\u7528\u6237\u80fd\u591f\u8bbf\u95ee\u654f\u611f\u8d44\u6e90\u3002<br \/>\n7.\u65e5\u5fd7\u8bb0\u5f55\uff1a\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u53ef\u4ee5\u5e2e\u52a9\u8bca\u65ad\u95ee\u9898\u548c\u76d1\u63a7\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\u3002Spring Boot \u9ed8\u8ba4\u4f7f\u7528 Logback \u4f5c\u4e3a\u65e5\u5fd7\u6846\u67b6\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u81ea\u5b9a\u4e49\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u603b\u4e4b\uff0cSpring Boot \u7684\u8bbe\u8ba1\u7406\u5ff5\u662f<strong>\u5f00\u7bb1\u5373\u7528<\/strong>\uff0c<strong>\u7b80\u5316\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u6784\u5efa\u548c\u90e8\u7f72\u8fc7\u7a0b<\/strong>\u3002\u901a\u8fc7<strong>\u5408\u9002\u7684\u6253\u5305\u65b9\u5f0f\u3001\u914d\u7f6e\u6587\u4ef6\u548c\u989d\u5916\u7684\u914d\u7f6e\u9009\u9879<\/strong>\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u5e76\u4e14\u901a\u8fc7\u76d1\u63a7\u548c\u7ba1\u7406\u529f\u80fd\u6765\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Using Spring Boot \u4f7f\u7528Spring Boot\u8fdb\u884c\u5f00\u53d1 (springdoc.cn) \u4e00 \u6784\u5efa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":167,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/165"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":3,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":170,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions\/170"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/167"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}