{"id":2892,"date":"2023-07-13T18:20:45","date_gmt":"2023-07-13T10:20:45","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=2892"},"modified":"2023-07-13T18:20:56","modified_gmt":"2023-07-13T10:20:56","slug":"spring-boot-%e6%9c%89%e5%93%aa%e4%ba%9b%e7%89%b9%e7%82%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-boot-%e6%9c%89%e5%93%aa%e4%ba%9b%e7%89%b9%e7%82%b9%ef%bc%9f\/","title":{"rendered":"Spring Boot \u6709\u54ea\u4e9b\u7279\u70b9\uff1f"},"content":{"rendered":"<link rel=\"stylesheet\" href=\"https:\/\/csdnimg.cn\/release\/blogv2\/dist\/mdeditor\/css\/editerView\/kdoc_html_views-1a98987dfd.css\">\n \t<link rel=\"stylesheet\" href=\"https:\/\/csdnimg.cn\/release\/blogv2\/dist\/mdeditor\/css\/editerView\/ck_htmledit_views-25cebea3f9.css\">\n<div id=\"content_views\" class=\"htmledit_views\">\n<p id=\"main-toc\"><strong>\u76ee\u5f55<\/strong><\/p>\n<p id=\"%E4%B8%80%E3%80%81%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:0px;\"><a href=\"#%E4%B8%80%E3%80%81%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE\" target=\"_blank\"  rel=\"nofollow\" >\u4e00\u3001\u81ea\u52a8\u914d\u7f6e<\/a><\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E5%B5%8C%E5%85%A5%E5%BC%8F%20Tomcat%20Web%20%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:0px;\"><a href=\"#%E4%BA%8C%E3%80%81%E5%B5%8C%E5%85%A5%E5%BC%8F%20Tomcat%20Web%20%E6%9C%8D%E5%8A%A1%E5%99%A8\" target=\"_blank\"  rel=\"nofollow\" >\u4e8c\u3001\u5d4c\u5165\u5f0f Tomcat Web \u670d\u52a1\u5668<\/a><\/p>\n<p id=\"%E4%B8%89%E3%80%81%E5%85%A5%E9%97%A8%20POM-toc\" style=\"margin-left:0px;\"><a href=\"#%E4%B8%89%E3%80%81%E5%85%A5%E9%97%A8%20POM\" target=\"_blank\"  rel=\"nofollow\" >\u4e09\u3001\u5165\u95e8 POM<\/a><\/p>\n<p id=\"%E5%9B%9B%E3%80%81Actuator%E6%89%A7%E8%A1%8C%E5%99%A8%20API-toc\" style=\"margin-left:0px;\"><a href=\"#%E5%9B%9B%E3%80%81Actuator%E6%89%A7%E8%A1%8C%E5%99%A8%20API\" target=\"_blank\"  rel=\"nofollow\" >\u56db\u3001Actuator\u6267\u884c\u5668 API<\/a><\/p>\n<p id=\"%E4%BA%94%E3%80%81SpringBoot%E5%88%9D%E5%A7%8B%E5%8C%96%E5%99%A8-toc\" style=\"margin-left:0px;\"><a href=\"#%E4%BA%94%E3%80%81SpringBoot%E5%88%9D%E5%A7%8B%E5%8C%96%E5%99%A8\" target=\"_blank\"  rel=\"nofollow\" >\u4e94\u3001SpringBoot\u521d\u59cb\u5316\u5668<\/a><\/p>\n<hr id=\"hr-toc\">\n<h1 id=\"%E4%B8%80%E3%80%81%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE\">\u4e00\u3001\u81ea\u52a8\u914d\u7f6e<\/h1>\n<p>Spring Boot\u7684\u81ea\u52a8\u914d\u7f6e\u662fSpring Boot\u6846\u67b6\u63d0\u4f9b\u7684\u4e00\u79cd\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u6839\u636e\u7528\u7a0b\u5e8f\u7684\u4f9d\u8d56\u548c\u914d\u7f6e\u4fe1\u606f\uff0c\u81ea\u52a8\u914d\u7f6e\u4e00\u4e9b\u5e38\u89c1\u7684\u529f\u80fd\u6a21\u5757\u3002\u8fd9\u6837\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u548c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u624b\u52a8\u914d\u7f6e\u5927\u91cf\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0cSpring Boot\u7684\u81ea\u52a8\u914d\u7f6e\u901a\u8fc7\u6761\u4ef6\u6ce8\u89e3\u548c\u81ea\u52a8\u914d\u7f6e\u7c7b\u5b9e\u73b0\u3002\u6761\u4ef6\u6ce8\u89e3\u7528\u4e8e\u6839\u636e\u7279\u5b9a\u7684\u6761\u4ef6\u6765\u51b3\u5b9a\u662f\u5426\u5e94\u7528\u67d0\u4e2a\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\uff0c\u800c\u81ea\u52a8\u914d\u7f6e\u7c7b\u5219\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684\u914d\u7f6e\u548c\u521d\u59cb\u5316\u4ee3\u7801\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86Spring Boot\u81ea\u52a8\u914d\u7f6e\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-java\">import org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\n@SpringBootApplication\npublic class MyApp {\n\n    @GetMapping(\"\/\")\n    public String hello() {\n        return \"Hello, Spring Boot!\";\n    }\n\n    public static void main(String[] args) {\n        SpringApplication.run(MyApp.class, args);\n    }\n}<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u4e86<code>@SpringBootApplication<\/code>\u6ce8\u89e3\u6765\u6807\u8bb0\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u7c7b\u3002\u8fd9\u4e2a\u6ce8\u89e3\u662fSpring Boot\u7684\u6838\u5fc3\u6ce8\u89e3\uff0c\u5b83\u5305\u542b\u4e86\u591a\u4e2a\u5176\u4ed6\u6ce8\u89e3\uff0c\u5176\u4e2d\u5305\u62ec<code>@EnableAutoConfiguration<\/code>\u6ce8\u89e3\uff0c\u7528\u4e8e\u542f\u7528\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\u3002<\/p>\n<p>\u5728<code>MyApp<\/code>\u7c7b\u4e2d\uff0c\u4f7f\u7528\u4e86<code>@RestController<\/code>\u6ce8\u89e3\u6765\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684RESTful\u63a5\u53e3\uff0c\u8fd9\u4e2a\u63a5\u53e3\u5bf9\u6839\u8def\u5f84(\"\/\")\u8fdb\u884cGET\u8bf7\u6c42\u65f6\uff0c\u8fd4\u56de\"Hello, Spring Boot!\"\u3002<\/p>\n<p>\u5728<code>main<\/code>\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528<code>SpringApplication.run()<\/code>\u65b9\u6cd5\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u4f1a\u81ea\u52a8\u6839\u636e\u7c7b\u8def\u5f84\u4e0a\u7684\u4f9d\u8d56\u548c\u914d\u7f6e\u4fe1\u606f\uff0c\u8fdb\u884c\u81ea\u52a8\u914d\u7f6e\u548c\u521d\u59cb\u5316\u3002<\/p>\n<p>\u901a\u8fc7Spring Boot\u7684\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u548c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u9700\u624b\u52a8\u914d\u7f6e\u5927\u91cf\u7684\u4ee3\u7801\uff0c\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"lazyload\"alt=\"\" height=\"785\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" width=\"1200\"><noscript><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"785\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png\" width=\"1200\"><\/noscript><\/p>\n<p>&nbsp;<\/p>\n<h1 id=\"%E4%BA%8C%E3%80%81%E5%B5%8C%E5%85%A5%E5%BC%8F%20Tomcat%20Web%20%E6%9C%8D%E5%8A%A1%E5%99%A8\">\u4e8c\u3001\u5d4c\u5165\u5f0f Tomcat Web \u670d\u52a1\u5668<\/h1>\n<p>SpringBoot\u7684\u5d4c\u5165\u5f0fTomcat Web\u670d\u52a1\u5668\u662f\u6307SpringBoot\u6846\u67b6\u5185\u7f6e\u7684\u4e00\u4e2a\u8f7b\u91cf\u7ea7Web\u670d\u52a1\u5668\uff0c\u5b83\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u800c\u65e0\u9700\u989d\u5916\u7684Web\u670d\u52a1\u5668\u73af\u5883\u3002\u5177\u4f53\u6765\u8bf4\uff0cSpringBoot\u7684\u5d4c\u5165\u5f0fTomcat\u670d\u52a1\u5668\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u7684JAR\u6587\u4ef6\uff0c\u5e76\u5305\u542b\u4e86Tomcat\u5bb9\u5668\u3002\u8fd9\u6837\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u8fd0\u884cJAR\u6587\u4ef6\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u901a\u8fc7\u5185\u7f6e\u7684Tomcat\u670d\u52a1\u5668\u63d0\u4f9bWeb\u670d\u52a1\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86SpringBoot\u5d4c\u5165\u5f0fTomcat\u670d\u52a1\u5668\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-java\">import org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\n@SpringBootApplication\npublic class MyApp {\n\n    @GetMapping(\"\/\")\n    public String hello() {\n        return \"Hello, SpringBoot!\";\n    }\n\n    public static void main(String[] args) {\n        SpringApplication.run(MyApp.class, args);\n    }\n}<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u4e86<code>@SpringBootApplication<\/code>\u6ce8\u89e3\u6765\u6807\u8bb0\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u7c7b\u3002\u5728<code>MyApp<\/code>\u7c7b\u4e2d\uff0c\u4f7f\u7528\u4e86<code>@RestController<\/code>\u6ce8\u89e3\u6765\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684RESTful\u63a5\u53e3\u3002\u5728<code>main<\/code>\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528<code>SpringApplication.run()<\/code>\u65b9\u6cd5\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5d4c\u5165\u5f0fTomcat\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u542f\u52a8\uff0c\u5e76\u76d1\u542c\u9ed8\u8ba4\u7684HTTP\u7aef\u53e3\uff08\u901a\u5e38\u4e3a8080\uff09\u3002\u5f53\u8bbf\u95ee\u6839\u8def\u5f84(\"\/\")\u65f6\uff0c\u5c06\u8fd4\u56de\"Hello, SpringBoot!\"\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u901a\u8fc7SpringBoot\u7684\u5d4c\u5165\u5f0fTomcat\u670d\u52a1\u5668\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u7684JAR\u6587\u4ef6\uff0c\u5e76\u76f4\u63a5\u8fd0\u884c\u5728\u5185\u7f6e\u7684Tomcat\u670d\u52a1\u5668\u4e2d\uff0c\u7b80\u5316\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u90e8\u7f72\u548c\u8fd0\u884c\u8fc7\u7a0b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"lazyload\"alt=\"\" height=\"1043\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820249d9da4786.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" width=\"1200\"><noscript><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1043\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820249d9da4786.png\" width=\"1200\"><\/noscript><\/p>\n<p>&nbsp;<\/p>\n<h1 id=\"%E4%B8%89%E3%80%81%E5%85%A5%E9%97%A8%20POM\">\u4e09\u3001\u5165\u95e8 POM<\/h1>\n<p>SpringBoot\u7684\u5165\u95e8POM\u662f\u6307\u7528\u4e8e\u6784\u5efaSpringBoot\u5e94\u7528\u7a0b\u5e8f\u7684\u9879\u76ee\u5bf9\u8c61\u6a21\u578b\uff08Project Object Model\uff09\uff0c\u5b83\u5b9a\u4e49\u4e86\u9879\u76ee\u7684\u4f9d\u8d56\u548c\u6784\u5efa\u914d\u7f6e\u4fe1\u606f\u3002\u5165\u95e8POM\u662fSpringBoot\u5b98\u65b9\u63d0\u4f9b\u7684\u4e00\u4e2a\u8d77\u6b65\u4f9d\u8d56\uff08Starter Dependency\uff09\uff0c\u53ef\u4ee5\u7b80\u5316\u9879\u76ee\u7684\u914d\u7f6e\u548c\u4f9d\u8d56\u7ba1\u7406\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5165\u95e8POM\u5305\u542b\u4e86SpringBoot\u6838\u5fc3\u4f9d\u8d56\u548c\u4e00\u4e9b\u5e38\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u4f9d\u8d56\uff0c\u4ee5\u53ca\u76f8\u5173\u7684\u63d2\u4ef6\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86SpringBoot\u7684\u5165\u95e8POM\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-XML\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n         xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n         xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n    \n    &lt;groupId&gt;com.example&lt;\/groupId&gt;\n    &lt;artifactId&gt;my-springboot-app&lt;\/artifactId&gt;\n    &lt;version&gt;1.0.0&lt;\/version&gt;\n    \n    &lt;parent&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n        &lt;version&gt;2.5.2&lt;\/version&gt;\n        &lt;relativePath\/&gt; &lt;!-- lookup parent from repository --&gt;\n    &lt;\/parent&gt;\n    \n    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n    \n    &lt;build&gt;\n        &lt;plugins&gt;\n            &lt;plugin&gt;\n                &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n                &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\n            &lt;\/plugin&gt;\n        &lt;\/plugins&gt;\n    &lt;\/build&gt;\n&lt;\/project&gt;<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>&lt;parent&gt;<\/code>\u6807\u7b7e\u6307\u5b9a\u4e86SpringBoot\u7684\u5165\u95e8POM\u4e3a\u7236\u9879\u76ee\uff0c\u5b83\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u7684\u4f9d\u8d56\u7ba1\u7406\u548c\u6784\u5efa\u914d\u7f6e\u3002<code>&lt;dependencies&gt;<\/code>\u6807\u7b7e\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a\u4f9d\u8d56\u9879\uff0c\u5373<code>spring-boot-starter-web<\/code>\uff0c\u5b83\u662fSpringBoot Web\u5e94\u7528\u7684\u8d77\u6b65\u4f9d\u8d56\uff0c\u5305\u542b\u4e86Web\u5f00\u53d1\u6240\u9700\u7684\u6838\u5fc3\u4f9d\u8d56\u3002<code>&lt;build&gt;<\/code>\u6807\u7b7e\u4e2d\u914d\u7f6e\u4e86\u4e00\u4e2a\u63d2\u4ef6\uff0c\u5373<code>spring-boot-maven-plugin<\/code>\uff0c\u5b83\u7528\u4e8e\u5c06\u9879\u76ee\u6253\u5305\u6210\u53ef\u6267\u884c\u7684JAR\u6587\u4ef6\u3002<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528SpringBoot\u7684\u5165\u95e8POM\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u7b80\u5316\u9879\u76ee\u7684\u4f9d\u8d56\u7ba1\u7406\u548c\u6784\u5efa\u914d\u7f6e\uff0c\u53ea\u9700\u58f0\u660e\u8d77\u6b65\u4f9d\u8d56\u5373\u53ef\u83b7\u53d6\u6240\u9700\u7684\u529f\u80fd\u548c\u4f9d\u8d56\u9879\u3002\u540c\u65f6\uff0c\u5165\u95e8POM\u63d0\u4f9b\u4e86\u4e00\u81f4\u7684\u9879\u76ee\u7ed3\u6784\u548c\u6784\u5efa\u65b9\u5f0f\uff0c\u65b9\u4fbf\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u4e0a\u624b\u548c\u5f00\u53d1SpringBoot\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"lazyload\"alt=\"\" height=\"640\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-25\/202307131820253838befb5.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" width=\"957\"><noscript><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"640\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-25\/202307131820253838befb5.png\" width=\"957\"><\/noscript><\/p>\n<h1>&nbsp;\u56db\u3001Actuator\u6267\u884c\u5668 API<\/h1>\n<p>SpringBoot\u7684Actuator\u6267\u884c\u5668API\u662f\u6307SpringBoot\u6846\u67b6\u63d0\u4f9b\u7684\u4e00\u7ec4\u7528\u4e8e\u76d1\u63a7\u548c\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f\u7684API\u63a5\u53e3\u3002\u901a\u8fc7Actuator\u6267\u884c\u5668API,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u5065\u5eb7\u72b6\u6001\u3001\u914d\u7f6e\u4fe1\u606f\u3001\u6027\u80fd\u6307\u6807\u7b49\uff0c\u5e76\u53ef\u4ee5\u8fdb\u884c\u52a8\u6001\u8c03\u6574\u548c\u7ba1\u7406\u3002\u5177\u4f53\u6765\u8bf4,Actuator\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217RESTful\u98ce\u683c\u7684\u7aef\u70b9\uff08Endpoints\uff09,\u901a\u8fc7HTTP\u8bf7\u6c42\u6765\u8bbf\u95ee\u8fd9\u4e9b\u7aef\u70b9\u53ef\u4ee5\u83b7\u53d6\u76f8\u5173\u7684\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801,\u5c55\u793a\u4e86SpringBoot\u7684Actuator\u6267\u884c\u5668API\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-XML\">&lt;dependencyManagement&gt;&lt;dependencies&gt;&lt;dependency&gt;&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;&lt;artifactId&gt;spring-boot-dependencies&lt;\/artifactId&gt;&lt;version&gt;2.5.2&lt;\/version&gt;&lt;type&gt;pom&lt;\/type&gt;&lt;scope&gt;import&lt;\/scope&gt;&lt;\/dependency&gt;&lt;\/dependencies&gt;&lt;\/dependencyManagement&gt;&lt;dependencies&gt;&lt;dependency&gt;&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;&lt;artifactId&gt;spring-boot-starter-actuator&lt;\/artifactId&gt;&lt;\/dependency&gt;&lt;\/dependencies&gt;<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d,\u901a\u8fc7\u5728\u9879\u76ee\u7684\u4f9d\u8d56\u7ba1\u7406\u4e2d\u6dfb\u52a0<code>spring-boot-starter-actuator<\/code>\u4f9d\u8d56,\u5373\u53ef\u5f15\u5165Actuator\u6267\u884c\u5668API\u3002\u901a\u8fc7Actuator\u6267\u884c\u5668API,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u8bbf\u95ee\u4e00\u4e9b\u5e38\u7528\u7684\u7aef\u70b9,\u4f8b\u5982\uff1a-&nbsp;<code>\/actuator\/health<\/code>\uff1a\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u5065\u5eb7\u72b6\u6001\u3002-&nbsp;<code>\/actuator\/info<\/code>\uff1a\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u4fe1\u606f\u3002-&nbsp;<code>\/actuator\/metrics<\/code>\uff1a\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u6307\u6807\u3002-&nbsp;<code>\/actuator\/env<\/code>\uff1a\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u73af\u5883\u914d\u7f6e\u3002-&nbsp;<code>\/actuator\/beans<\/code>\uff1a\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u6240\u6709Bean\u4fe1\u606f\u3002\u901a\u8fc7\u8bbf\u95ee\u8fd9\u4e9b\u7aef\u70b9,\u53ef\u4ee5\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7684\u76f8\u5173\u4fe1\u606f,\u5e76\u8fdb\u884c\u76d1\u63a7\u548c\u7ba1\u7406\u3002\u540c\u65f6,Actuator\u8fd8\u652f\u6301\u81ea\u5b9a\u4e49\u7aef\u70b9,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u7aef\u70b9\u3002\u901a\u8fc7SpringBoot\u7684Actuator\u6267\u884c\u5668API,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u65b9\u4fbf\u5730\u76d1\u63a7\u548c\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f,\u5b9e\u73b0\u66f4\u597d\u7684\u8fd0\u7ef4\u548c\u8c03\u4f18\u3002<\/p>\n<h1 id=\"%E4%BA%94%E3%80%81SpringBoot%E5%88%9D%E5%A7%8B%E5%8C%96%E5%99%A8\">\u4e94\u3001SpringBoot\u521d\u59cb\u5316\u5668<\/h1>\n<p>SpringBoot\u7684\u521d\u59cb\u5316\u5668\u662f\u6307\u7528\u4e8e\u521d\u59cb\u5316SpringBoot\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u7ec4\u63a5\u53e3\u548c\u7c7b\u3002\u901a\u8fc7\u5b9e\u73b0\u8fd9\u4e9b\u521d\u59cb\u5316\u5668,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u6267\u884c\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u521d\u59cb\u5316\u64cd\u4f5c,\u4f8b\u5982\u52a0\u8f7d\u914d\u7f6e\u3001\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\u7b49\u3002\u5177\u4f53\u6765\u8bf4,\u521d\u59cb\u5316\u5668\u4f7f\u7528<code>ApplicationContextInitializer<\/code>\u63a5\u53e3\u6765\u5b9a\u4e49\u521d\u59cb\u5316\u903b\u8f91,\u5e76\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u88abSpringBoot\u6846\u67b6\u81ea\u52a8\u8c03\u7528\u3002<\/p>\n<p><code>MyApp<\/code>\u7c7b\u5b9e\u73b0\u4e86<code>ApplicationContextInitializer<\/code>\u63a5\u53e3,\u5e76\u91cd\u5199\u4e86<code>initialize()<\/code>\u65b9\u6cd5\u3002\u5728<code>initialize()<\/code>\u65b9\u6cd5\u4e2d,\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u521d\u59cb\u5316\u903b\u8f91\u3002\u5728<code>main<\/code>\u65b9\u6cd5\u4e2d,\u901a\u8fc7<code>SpringApplication<\/code>\u7684<code>addInitializers()<\/code>\u65b9\u6cd5\u5c06<code>MyApp<\/code>\u521d\u59cb\u5316\u5668\u6dfb\u52a0\u5230SpringApplication\u4e2d\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6,\u4f1a\u81ea\u52a8\u6267\u884c\u521d\u59cb\u5316\u5668\u4e2d\u7684\u903b\u8f91\u3002\u901a\u8fc7SpringBoot\u7684\u521d\u59cb\u5316\u5668,\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u81ea\u5b9a\u4e49\u7684\u521d\u59cb\u5316\u64cd\u4f5c,\u4f8b\u5982\u52a0\u8f7d\u914d\u7f6e\u3001\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\u7b49\u3002\u521d\u59cb\u5316\u5668\u53ef\u4ee5\u4e0e\u5176\u4ed6SpringBoot\u7279\u6027\uff08\u5982\u914d\u7f6e\u6587\u4ef6\u3001\u4f9d\u8d56\u6ce8\u5165\u7b49\uff09\u7ed3\u5408\u4f7f\u7528,\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u5e94\u7528\u7a0b\u5e8f\u521d\u59cb\u5316\u3002<\/p>\n<\/div>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8eCSDN\uff1ahttps:\/\/blog.csdn.net\/yangyin1998\/article\/details\/131673433<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u4e00\u3001\u81ea\u52a8\u914d\u7f6e \u4e8c\u3001\u5d4c\u5165\u5f0f Tomcat Web \u670d\u52a1\u5668 \u4e09\u3001\u5165\u95e8 POM \u56db\u3001Actuator\u6267\u884c\u5668 API \u4e94\u3001Sprin &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-2892","post","type-post","status-publish","format-standard","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820240707f2ab4.png","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820249d9da4786.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-24\/202307131820249d9da4786.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-25\/202307131820253838befb5.png","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/default\/nine\/2023-07-13\/18-20-25\/202307131820253838befb5.png","id":"image5"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2023-07-13","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":364,"next_post_id":2894,"next_post_title":"Feign\u7b2c\u4e00\u6b21\u8c03\u7528\u4e3a\u4ec0\u4e48\u4f1a\u5f88\u6162\uff1f","previous_post_id":2568,"previous_post_title":"SpringBoot \u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u52a8\u6001\u7ba1\u7406\uff0c\u592a\u723d\u4e86\uff01","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2892"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2892\/revisions"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}