{"id":10020423,"date":"2024-11-28T13:44:36","date_gmt":"2024-11-28T05:44:36","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020423"},"modified":"2024-11-28T13:44:36","modified_gmt":"2024-11-28T05:44:36","slug":"spring-boot-3-4-%e6%ad%a3%e5%bc%8f%e5%8f%91%e5%b8%83%ef%bc%8c%e7%8e%8b%e7%82%b8%e7%ba%a7%e6%9b%b4%e6%96%b0%ef%bc%81","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020423","title":{"rendered":"Spring Boot 3.4 \u6b63\u5f0f\u53d1\u5e03\uff0c\u738b\u70b8\u7ea7\u66f4\u65b0\uff01"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662fR\u54e5\u3002<\/p>\n<p>\u6700\u65b0\u6d88\u606f\uff0cSpring Boot \u4e00\u6b21\u6027\u53d1\u5e03\u4e86 6 \u4e2a\u7248\u672c\uff1a<\/p>\n<ul>\n<li><strong>3.4.0<\/strong><\/li>\n<li><strong>3.3.6<\/strong><\/li>\n<li>3.2.12<\/li>\n<li>3.1.14<\/li>\n<li>3.0.18<\/li>\n<li>2.7.23<\/li>\n<\/ul>\n<p>Spring Boot 3.4 \u6b63\u5f0f\u53d1\u5e03\u4e86\uff0c3.2.x \u5728\u524d\u51e0\u5929\u4e5f\u505c\u6b62\u7ef4\u62a4\u4e86\uff0c\u5f88\u795e\u5947\u7684\u662f\uff0c3.1.x \u53ca\u4ee5\u4e0b\u7684\u505c\u66f4\u7248\u672c\u5c45\u7136\u4e5f\u53d1\u5e03 bug \u66f4\u65b0\u5305\u4e86\u3002<\/p>\n<p><strong>\u6700\u65b0\u7684\u652f\u6301\u7248\u672c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"324\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVde614\" alt=\"\" title=\"\"><\/p>\n<p>\u4ece\u8def\u7ebf\u56fe\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a\u7248\u672c\u7684\u7ec8\u6b62\u65f6\u95f4\uff0c\u6bcf\u4e2a\u7248\u672c\u7684\u751f\u547d\u5468\u671f\u53ea\u6709\u4e00\u5e74\u3002<\/p>\n<p>Spring Boot \u8fdb\u5165\u4e86\u5168\u65b0\u7684 3.3+ \u65f6\u4ee3\u4e86\uff0c<strong>3.2.x \u53ca\u4e4b\u524d\u7684\u7248\u672c\u4e5f\u90fd\u505c\u6b62\u7ef4\u62a4\u4e86\uff0c\u5546\u4e1a\u652f\u6301\u7684\u7248\u672c\u4e5f\u53ea\u6709 2.7+ \u4e86<\/strong>\uff0c2.6.x \u4ee5\u4e0b\u7684\u7248\u672c\u5f7b\u5e95\u9000\u51fa\u5386\u53f2\u821e\u53f0\uff0c\u6280\u672f\u53d8\u9769\u592a\u5feb\u4e86\u3002\u3002<\/p>\n<h2>Spring Boot 3.4.0 \u65b0\u7279\u6027<\/h2>\n<h3>1\u3001\u6700\u4f4e\u73af\u5883\u8981\u6c42<\/h3>\n<p>Spring Boot 3.0.0 \u5f00\u59cb\u652f\u6301\u5e76\u6700\u4f4e\u8981\u6c42 Java 17\uff0c\u76ee\u524d\u7684\u65b0\u7248\u672c\u4e5f\u9646\u7eed\u5f00\u59cb\u652f\u6301 Java 21 ~ 23 \u4e86\u3002<\/p>\n<p><strong>\u5bf9 Java \u5f00\u53d1\u73af\u5883\u7684\u8981\u6c42\u5bf9\u6bd4\u8868\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>Spring Boot<\/th>\n<th>JDK<\/th>\n<th>Spring<\/th>\n<th>Maven<\/th>\n<th>Gradle<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>3.4.0<\/td>\n<td>16 ~ 23<\/td>\n<td>6.2.0+<\/td>\n<td>3.6.3+<\/td>\n<td>7.6.4+,8.4+<\/td>\n<\/tr>\n<tr>\n<td>3.3.0<\/td>\n<td>17 ~ 22<\/td>\n<td>6.1.8+<\/td>\n<td>3.6.3+<\/td>\n<td>7.5+,8.x<\/td>\n<\/tr>\n<tr>\n<td>3.2.0<\/td>\n<td>17 ~ 21<\/td>\n<td>6.1.1+<\/td>\n<td>3.6.3+<\/td>\n<td>7.5+,8.x<\/td>\n<\/tr>\n<tr>\n<td>3.1.0<\/td>\n<td>17 ~ 20<\/td>\n<td>6.0.9+<\/td>\n<td>3.6.3+<\/td>\n<td>7.5+,8.x<\/td>\n<\/tr>\n<tr>\n<td>3.0.0<\/td>\n<td>17 ~ 19<\/td>\n<td>6.0.2+<\/td>\n<td>3.5+<\/td>\n<td>7.5+<\/td>\n<\/tr>\n<tr>\n<td>2.7.12<\/td>\n<td>8 ~ 20<\/td>\n<td>5.3.27+<\/td>\n<td>3.5+<\/td>\n<td>6.8.x, 6.9.x, 7.x, 8.x<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u652f\u6301 Java 8 \u7684\u6700\u540e\u4e00\u4e2a Spring Boot 2.x \u7cfb\u5217\u7248\u672c\u5df2\u7ecf\u9000\u4f0d\u5566\uff0cJava 17 \u7684\u65b0\u65f6\u4ee3\u5230\u6765\u3002<\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u505c\u7559\u5728 Java 8 \u5c31 OUT \u4e86\uff0c\u8fc7\u53bb\u4e00\u4e24\u5e74\uff0cJava 8 \u91c7\u7528\u7387\u8170\u65a9\uff0cJava 17 \u66b4\u6da8 430%\uff01\uff01<\/p>\n<blockquote><p>R\u54e5\u5236\u4f5c\u7684\u300a<a href=\"https:\/\/link.segmentfault.com\/?enc=kTRkjOafAQBjMrD4hH3JBQ%3D%3D.gDG1CzjO0H9dqMrNzUnmKIBDicZKf53RcBt3iEu0D5rrTwT6j%2B50dcVbQeDufDBViXV63lS677fZK%2B8osI59ww%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Java \u65b0\u7279\u6027\u5b9e\u6218\u8bfe<\/a>\u300b\u90fd\u53ef\u4ee5\u62a5\u540d\u5b66\u8d77\u6765\uff0c\u597d\u8bfe\u4e0d\u8d35\uff0c199 \u5143\u6c38\u4e45\u5b66\u4e60\uff0c\u5982\u540e\u7eed\u51fa\u4e86 Java 21 \u53ca\u66f4\u591a\u7248\u672c\u65b0\u5185\u5bb9\u90fd\u80fd\u514d\u8d39\u66f4\u65b0\u3002<\/p><\/blockquote>\n<h3>2\u3001\u7ed3\u6784\u5316\u65e5\u5fd7<\/h3>\n<h4>\u4ec0\u4e48\u662f\u7ed3\u6784\u5316\u65e5\u5fd7\uff1f<\/h4>\n<p>\u4e00\u822c\u7684\u65e5\u5fd7\u90fd\u662f \u201c<strong>\u975e\u7ed3\u6784<\/strong>\u201d \u5316\u7684\uff0c\u4e5f\u5c31\u662f\u4e00\u6bb5\u6ca1\u6709\u4efb\u4f55 \u201c<strong>\u7ed3\u6784<\/strong>\u201d \u7684\u65e5\u5fd7\u6587\u672c\u5b57\u7b26\u4e32\uff0c\u6bd4\u5982\u6211\u4eec\u5728\u7cfb\u7edf\u4e2d\u5e38\u89c1\u7684\u65e5\u5fd7\u4fe1\u606f\uff1a<\/p>\n<pre><code>2024-11-25 10:41:05:347 INFO ...<\/code><\/pre>\n<p>\u867d\u7136\u5305\u542b\u4e86\u6240\u6709\u5173\u952e\u7684\u4fe1\u606f\uff0c\u4f46\u662f\u60f3\u8981\u63d0\u53d6\u5176\u4e2d\u7684\u7279\u5b9a\u4fe1\u606f\u5c31\u975e\u5e38\u56f0\u96be\uff0c\u9700\u8981\u89e3\u6790\u548c\u641c\u7d22\u8fd9\u6bb5\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u800c\u7ed3\u6784\u5316\u65e5\u5fd7\u5219\u662f\u4e00\u6bb5\u6709\u660e\u786e\u5b9a\u4e49\u7684\u7ed3\u6784\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u8bfb\u6027\u597d\uff0c\u901a\u7528\u662f <strong>JSON<\/strong> \u683c\u5f0f\uff0c\u5982\u4ee5\u4e0b\u65e5\u5fd7\uff1a<\/p>\n<pre><code>{\n    &quot;timestamp&quot;: &quot;2024-11-25 10:41:05:347&quot;,\n    &quot;level&quot;: &quot;INFO&quot;,\n    ...\n}<\/code><\/pre>\n<p>\u8fd9\u6837\u83b7\u53d6\u65e5\u5fd7\u4fe1\u606f\u662f\u4e0d\u662f\u65b9\u4fbf\u591a\u4e86\uff1f<\/p>\n<h4>Spring Boot \u4e2d\u7684\u7ed3\u6784\u5316\u65e5\u5fd7<\/h4>\n<p>Spring Boot 3.4 \u652f\u6301\u7ed3\u6784\u5316\u65e5\u5fd7\u8bb0\u5f55\uff0c\u5e76\u652f\u6301\u4ee5\u4e0b\u5f00\u7bb1\u5373\u7528\u7684 <strong>JSON<\/strong> \u683c\u5f0f\uff1a<\/p>\n<ul>\n<li>Elastic Common Schema (<strong>ecs<\/strong>)<\/li>\n<li>Graylog Extended Log Format (<strong>gelf<\/strong>)<\/li>\n<li>Logstash\uff08<strong>logstash<\/strong>\uff09<\/li>\n<\/ul>\n<p>\u542f\u7528\u7ed3\u6784\u5316\u65e5\u5fd7\u8bb0\u5f55\u914d\u7f6e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>logging.structured.format.console<\/td>\n<td>\u7528\u4e8e\u63a7\u5236\u53f0\u8f93\u51fa<\/td>\n<\/tr>\n<tr>\n<td>logging.structured.format.file<\/td>\n<td>\u7528\u4e8e\u6587\u4ef6\u8f93\u51fa<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"yaml\">logging:\n  structured:\n    format:\n      console: ecs\n      file: ecs<\/code><\/pre>\n<p>\u7ed3\u6784\u5316\u65e5\u5fd7\u914d\u7f6e\u652f\u6301\u4e0a\u9762\u6240\u8bf4\u7684 <strong>ecs\u3001gelf\u3001logstash<\/strong> \u65e5\u5fd7\u3002<\/p>\n<blockquote><p>\u63a8\u8350\u770b\u770b\u6211\u5199\u7684\u66f4\u591a Spring Boot \u6559\u7a0b\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=Q7EmcuTXK4LRNiQtNNIw%2Fg%3D%3D.%2BJcJM%2BKYkbdmRlTesFi3A0BQyfLepOftofPMFqdLqvA0YVnKDAACl7qFw6e2rpye\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.javastack.cn\/spring\/spring-boot\/<\/a><\/p><\/blockquote>\n<h3>3\u3001\u5b9a\u4e49\u9644\u52a0\u7684 Bean<\/h3>\n<p>Spring Boot 3.4 \u5f00\u59cb\uff0c\u5f53\u7c7b\u578b\u5339\u914d\u65f6\uff0c\u57fa\u4e8e Bean \u7684\u6761\u4ef6\u73b0\u5728\u5c06\u5ffd\u7565\u4efb\u4f55\u4e0d\u662f\u9ed8\u8ba4\u5019\u9009\u8005\u7684 Bean\u3002<\/p>\n<p>\u901a\u8fc7\u58f0\u660e bean \u4e0d\u662f\u9ed8\u8ba4\u5019\u9009\u8005\uff0c\u5982\uff1a<\/p>\n<pre><code class=\"java\">@Bean(defaultCandidate = false)\npublic class Xxx {\n    \n}<\/code><\/pre>\n<p>\u7136\u540e\u5728\u5b9a\u4e49\u81ea\u52a8\u914d\u7f6e\u7c7b\u578b\u7684 bean \u65f6\uff0c<strong>\u5982\u679c\u5b58\u5728\u76f8\u540c\u7c7b\u578b\u7684 bean\uff0c\u5b83\u5c31\u4f1a\u88ab\u5ffd\u7565\uff0c\u4ece\u800c\u4e0d\u4f1a\u5bfc\u81f4\u81ea\u52a8\u914d\u7f6e\u7684 bean \u6ce8\u518c\u5931\u8d25<\/strong>\u3002<\/p>\n<p>\u6bd4\u5982\u5728\u540c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8981\u4f7f\u7528\u4e24\u4e2a\u6570\u636e\u6e90 Bean\uff0c\u6216\u8005\u5176\u4ed6\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u7684 Bean \u65f6\uff0c\u8fd9\u6837\u5c31\u7279\u522b\u6709\u7528\uff0c\u8fd8\u80fd\u7b80\u5316\u914d\u7f6e\u3002<\/p>\n<p>Spring Boot \u6700\u65b0\u6700\u5168\u7684\u5b9e\u6218\u4ee3\u7801\u5df2\u4e0a\u4f20 Github\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=ZTl6L2XFjm9lKEf7FP8fbw%3D%3D.Q4bUczeivp3smcPs5z2xfCQ5xlmbmwx4YYbMz%2BiygY3BE%2F3Kkp0wDAOQ6reZ2QeAmh8Vi3QrSQsalSydrpOvog%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/javastacks\/spring-boot-best-practice<\/a><\/p><\/blockquote>\n<h3>4\u3001\u6269\u5c55\u865a\u62df\u7ebf\u7a0b<\/h3>\n<p>Spring Boot 3.4 \u5f00\u59cb\uff0c\u5982\u679c\u542f\u7528\u4e86\u865a\u62df\u7ebf\u7a0b\uff0c\u4ee5\u4e0b\u7ec4\u4ef6\u5c06\u4f7f\u7528\u865a\u62df\u7ebf\u7a0b\uff1a<\/p>\n<ul>\n<li>OtlpMeterRegistry<\/li>\n<li>Undertow web server<\/li>\n<\/ul>\n<p>\u53e6\u5916\uff0c\u901a\u8fc7 Spring Integration \u96c6\u6210\u7684\u4efb\u52a1\u8c03\u5ea6\u5668\uff08TaskScheduler\uff09\u73b0\u5728\u4e5f\u662f\u865a\u62df\u7ebf\u7a0b\u611f\u77e5\u7684\uff0c\u5373\u4f7f\u5728 <code>@EnableScheduling<\/code> \u5728\u6ca1\u6709\u5f00\u542f\u7684\u72b6\u6001\u4e0b\u3002<\/p>\n<h3>5\u3001Docker Compose \u548c Testcontainers \u6539\u8fdb<\/h3>\n<p>Docker Compose \u73b0\u5728\u652f\u6301\u591a\u4e2a Docker Compose \u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u4e14\u6dfb\u52a0\u4e86\u51e0\u4e2a\u65b0\u7684\u547d\u4ee4\u884c\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><code>spring.docker.compose.start.arguments<\/code> \u548c <code>spring.docker.compose.stop.arguments<\/code> \u53c2\u6570\u53ef\u7528\u4e8e\u6307\u5b9a\u5728\u542f\u52a8\u548c\u505c\u6b62\u670d\u52a1\u65f6\u4f20\u9012\u7ed9 Docker Compose \u5b50\u547d\u4ee4\u7684\u5176\u4ed6\u547d\u4ee4\u884c\u53c2\u6570\u3002<\/li>\n<li><code>spring.docker.compose.arguments<\/code> \u53c2\u6570\u652f\u6301\u4f20\u9012\u53c2\u6570\u7ed9 Docker Compose\u3002<\/li>\n<\/ul>\n<p>\u53e6\u5916\uff0cTestcontainers \u6d4b\u8bd5\u5bb9\u5668\u4e5f\u5f97\u5230\u4e86\u5404\u79cd\u6539\u8fdb\uff0c\u6bd4\u5982\u6dfb\u52a0\u4e86\u5bf9 <code>org.testcontainers.kafka.KafkaContainer<\/code> \u3001Redis Stack \u548c Redis Stack Server \u7684\u652f\u6301\u3002<\/p>\n<h3>6\u3001Actuator \u589e\u5f3a<\/h3>\n<h4>\u53ef\u63d2\u62d4\u7684 Actuator \u66b4\u9732\u5668<\/h4>\n<p>Spring Boot 3.4 \u652f\u6301\u6269\u5c55 Spring Boot \u4ee5\u53ef\u63d2\u62d4\u7684\u65b9\u5f0f\u516c\u5f00 Actuator \u7aef\u70b9\uff0c\u5e76\u4e14\u6dfb\u52a0\u4e86\u4e00\u4e2a <code>EndpointExposureOutcomeContributor<\/code> \u63a5\u53e3\uff0c\u5b83\u4f1a\u5f71\u54cd\u5230 <code>@ConditionalOnAvailableEndpoint<\/code> \u6ce8\u89e3\u7684\u6761\u4ef6\u63a7\u5236\u3002<\/p>\n<p>\u6b64\u6269\u5c55\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u63d0\u4f9b\u7c7b\u4f3c\u4e8e\u6211\u4eec\u73b0\u6709\u7684 Cloud Foundry \u652f\u6301\u7684\u5176\u4ed6\u5e73\u53f0\u96c6\u6210\u3002<\/p>\n<h4>SSL\u4fe1\u606f\u548c\u5065\u5eb7\u68c0\u67e5<\/h4>\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u4e86 SSL bundles\uff0c\u73b0\u5728\u5728 <code>\/actuator\/info<\/code> \u4e0b\u6dfb\u52a0\u4e86\u4e00\u4e2a\u65b0\u7aef\u70b9\uff0c\u7528\u6765\u663e\u793a SSL \u4fe1\u606f\uff0c\u6bd4\u5982\u8bc1\u4e66\u6709\u6548\u671f\u3001\u9881\u53d1\u8005\u3001\u4e3b\u9898\u7b49\u3002<\/p>\n<p>\u8fd9\u4e2a\u7aef\u70b9\u8fd8\u80fd\u663e\u793a\u5373\u5c06\u8fc7\u671f\u7684\u8bc1\u4e66\uff0c\u8fd9\u6837\u5c31\u80fd\u63d0\u9192\u6211\u4eec\u4e0d\u5b9a\u671f\u66f4\u65b0\u8bc1\u4e66\uff0c\u5b83\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u63d0\u9192\u9608\u503c\u914d\u7f6e\u53c2\u6570\uff1a<\/p>\n<blockquote><p>management.health.ssl.certificate-validity-warning-threshold<\/p><\/blockquote>\n<p>\u53e6\u5916\uff0c\u5b83\u8fd8\u6dfb\u52a0\u4e86\u76d1\u63a7 SSL \u8bc1\u4e66\u7684\u5065\u5eb7\u68c0\u67e5\uff0c\u5982\u679c\u8bc1\u4e66\u65e0\u6548\uff0c\u5219\u4f1a\u5c06\u72b6\u6001\u8bbe\u7f6e\u4e3a\u4e2d\u6b62\u670d\u52a1\uff08OUT_OF_SERVICE\uff09\u3002<\/p>\n<h4>\u8ba1\u5212\u4efb\u52a1\u7aef\u70b9\u663e\u793a\u66f4\u591a\u4fe1\u606f<\/h4>\n<p>\u8ba1\u5212\u4efb\u52a1 <code>\/actuator\/scheduledtask<\/code> \u7aef\u70b9\u73b0\u5728\u6dfb\u52a0\u4e86\u66f4\u591a\u5173\u4e8e\u8ba1\u5212\u4efb\u52a1\u7684\u5143\u6570\u636e\u4fe1\u606f\uff0c\u6bd4\u5982\uff1a\u4e0b\u4e00\u6b21\u8ba1\u5212\u6267\u884c\u65f6\u95f4\u3001\u4e0a\u6b21\u6267\u884c\u65f6\u95f4\u3001\u72b6\u6001\u548c\u5f02\u5e38\u7b49\u3002<\/p>\n<h3>7\u3001\u955c\u50cf\u6784\u5efa\u6539\u8fdb<\/h3>\n<p>Spring Boot \u73b0\u5728\u9ed8\u8ba4\u4f7f\u7528\u7684\u662f <code>paketobuildpacks\/builder-jammy-java-tiny<\/code>\uff0c\u8be5\u6784\u5efa\u5668\u652f\u6301 ARM \u548c x64 \u5e73\u53f0\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n<p>\u5728 Maven \u548c Gradle \u63d2\u4ef6\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa OCI \u6620\u50cf\u7684 <code>trustBuilder<\/code> \u9009\u9879\uff0c\u5b83\u63a7\u5236\u4e86 CNB \u751f\u547d\u5468\u671f\u7684\u8c03\u7528\u65b9\u5f0f\uff0c\u4ece\u800c\u5728\u4f7f\u7528\u6765\u81ea\u4e0d\u53d7\u4fe1\u4efb\u6765\u6e90\u7684\u6784\u5efa\u5668\u65f6\u63d0\u4f9b\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u3002<\/p>\n<blockquote><p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6765\u81ea <strong>Paketo\u3001Heroku \u548c Google<\/strong> \u7684\u6784\u5efa\u5668\u662f\u53d7\u4fe1\u4efb\u7684\u3002<\/p><\/blockquote>\n<p>\u5728 Maven \u548c Gradle \u63d2\u4ef6\u4e2d\u8fd8\u6dfb\u52a0\u4e86\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa OCI \u6620\u50cf\u7684 <code>imagePlatform<\/code> \u9009\u9879\uff0c\u6b64\u9009\u9879\u53ef\u7528\u4e8e\u6307\u5b9a\u4e3a\u8fd0\u884c CNB \u6784\u5efa\u5305\u800c\u62c9\u53d6\u7684\u4efb\u4f55 CNB \u6784\u5efa\u5668\u3001\u8fd0\u884c\u548c\u6784\u5efa\u5305\u6620\u50cf\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c\u4f53\u7cfb\u7ed3\u6784\u3002<\/p>\n<h3>8\u3001MockMvcTester \u81ea\u52a8\u914d\u7f6e<\/h3>\n<p>\u652f\u6301\u5f53 <code>AssertJ<\/code> \u5728\u7c7b\u8def\u5f84\u4e0b\u65f6\u81ea\u52a8\u914d\u7f6e MockMvcTester\uff0c\u6709\u4e86 MockMvcTester\uff0c\u6211\u4eec\u5c31\u80fd\u4f7f\u7528\u6d41\u5f0f API \u5b9a\u4e49\u8bf7\u6c42\u548c\u65ad\u8a00\u3002<\/p>\n<p>MockMvcTester \u4e5f\u662f MockMvc \u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u5b83\u53ef\u4ee5\u4ee3\u66ff MockMvc \u6240\u80fd\u4f7f\u7528\u5230\u7684\u4efb\u4f55\u573a\u666f\u3002<\/p>\n<h3>9\u3001RestClient \u548c RestTemplate<\/h3>\n<p>RestClient \u548c RestTemplate \u7684\u81ea\u52a8\u914d\u7f6e\uff0c\u6dfb\u52a0\u4e86\u5bf9 Netty \u54cd\u5e94\u5f0f\u7684 <code>HttpClient<\/code> HTTP \u5ba2\u6237\u7aef\u548c JDK \u7684 <code>HttpClient<\/code> HTTP \u5ba2\u6237\u7aef\u7684\u652f\u6301\u3002<\/p>\n<p>\u6309\u7167\u4f18\u5148\u987a\u5e8f\u5206\u522b\u662f\uff1a<\/p>\n<ul>\n<li>Apache HTTP Components (<code>HttpComponentsClientHttpRequestFactory<\/code>)<\/li>\n<li>Jetty Client (<code>JettyClientHttpRequestFactory<\/code>)<\/li>\n<li>Reactor Netty <code>HttpClient<\/code> (<code>ReactorClientHttpRequestFactory<\/code>)<\/li>\n<li>JDK <code>HttpClient<\/code> (<code>JdkClientHttpRequestFactory<\/code>)<\/li>\n<li>Simple JDK <code>HttpURLConnection<\/code> (<code>SimpleClientHttpRequestFactory<\/code>)<\/li>\n<\/ul>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u5728\u7c7b\u8def\u5f84\u4e0a\u6ca1\u6709HTTP\u5ba2\u6237\u7aef\u5e93\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4f7f\u7528 JdkClientHttpRequestFactory\uff0c\u800c\u4ee5\u524d\u4f7f\u7528\u7684\u662f SimpleClientHttpRequestFactory\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e <code>spring.http.client.factory<\/code> \u53c2\u6570\u6765\u9009\u62e9\u7279\u5b9a\u7684 HTTP \u5ba2\u6237\u7aef\uff0c\u652f\u6301\u7684\u503c\u6709\uff1ahttp-components\u3001jetty\u3001reactor\u3001jdk \u548c simple\u3002<\/p>\n<h3>10\u3001\u4f18\u96c5\u5173\u673a<\/h3>\n<p>Spring Boot 3.4 \u5f00\u59cb\uff0c\u73b0\u5728\u9ed8\u8ba4\u542f\u7528\u5d4c\u5165\u5f0f Web \u670d\u52a1\u5668\u7684\u4f18\u96c5\u5173\u673a\uff0c\u5305\u62ec\uff1aJ<strong>etty\u3001Rector Netty\u3001Tomcat \u548c Undertow<\/strong>\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u6062\u590d\u4e4b\u524d\u7684\u9ed8\u8ba4\u884c\u4e3a\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<pre><code class=\"yaml\">server.shutdown: immediate<\/code><\/pre>\n<h3>11\u3001\u66f4\u591a<\/h3>\n<p>1\uff09Spring Boot \u4e0d\u518d\u4f9d\u8d56 OkHttp\uff0cOkHttp \u7684\u4f9d\u8d56\u4e5f\u88ab\u79fb\u9664\u4e86\u3002<\/p>\n<p>2\uff09Apache HTTP \u7ec4\u4ef6\u5df2\u66f4\u6539 <code>HttpClient<\/code> \u4e2d\u4e0e HTTP\/1.1 TLS \u5347\u7ea7\u76f8\u5173\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>3\uff09\u914d\u7f6e\u5c5e\u6027\u7684 Bean \u9a8c\u8bc1\u6709\u53d8\u52a8\uff0c\u5982\u679c\u8981\u9a8c\u8bc1\u7ea7\u8054\u5230\u5d4c\u5957\u5c5e\u6027\uff0c\u5219\u6839\u636e\u9700\u8981\u6dfb\u52a0 <code>@Valid<\/code> \u6ce8\u89e3\u3002<\/p>\n<p>4\uff09\u5f53\u5728 <code>@Bean<\/code> \u65b9\u6cd5\u4e0a\u4f7f\u7528 <code>@ConditionalOnBean<\/code> \u548c <code>@ConditionalOnMissingBean<\/code> \u5e76\u8bbe\u7f6e <code>annotation<\/code> \u5c5e\u6027\u65f6\uff0c <code>@ConditionalOnBean<\/code> \u548c <code>@ConditionalOnMissingBean<\/code> \u7684\u884c\u4e3a\u5df2\u66f4\u6539\u3002<\/p>\n<p>5\uff09\u5927\u91cf Spring \u5e93\u548c\u7b2c\u4e09\u65b9\u7c7b\u5e93\u90fd\u5f97\u5230\u4e86\u66f4\u65b0\uff0c\u8fd8\u6709\u4e00\u4e9b\u5e9f\u9664\u9879\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>Spring Boot 3.4 \u8fd9\u4e2a\u7248\u672c\u7684\u53d8\u5316\u8fd8\u633a\u5927\u7684\uff0c\u589e\u52a0\u4e86\u4e0d\u5c11\u5b9e\u7528\u529f\u80fd\uff0c\u5f88\u591a\u529f\u80fd\u4e5f\u90fd\u5f97\u5230\u4e86\u589e\u5f3a\uff0c\u505a\u6280\u672f\u7684\u771f\u8981\u65f6\u523b\u4fdd\u6301\u5bf9\u65b0\u6280\u672f\u7684\u6e34\u671b\u554a\uff0c\u4e0d\u7136\u90fd\u8ddf\u4e0d\u4e0a\u65f6\u4ee3\u7684\u6b65\u4f10\u4e86\u3002<\/p>\n<p><strong>\u8bdd\u8bf4\u4f60\u4eec\u73b0\u5728\u7528\u7684\u4ec0\u4e48\u7248\u672c\u5462\uff1f<\/strong><\/p>\n<p>Spring Boot \u6700\u65b0\u6700\u5168\u7684\u5b9e\u6218\u4ee3\u7801\u5df2\u4e0a\u4f20 Github\uff1a<\/p>\n<blockquote><p><a href=\"https:\/\/link.segmentfault.com\/?enc=NluMOHFiH9FzoaJlUucqvQ%3D%3D.TtqyAiPoofY9H0kwlfAHxyfXuvfm9cVOw2UEXOSF1BefqQXfu8Wi8kT1joAJ7NipUGgegx7Jz4lHehrqIccGbQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/javastacks\/spring-boot-best-practice<\/a><\/p><\/blockquote>\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u7528\u8fc7 Spring Boot\uff0c\u8fd9\u91cc\u63a8\u8350\u4e0b\u6211\u7684\u300a<a href=\"https:\/\/link.segmentfault.com\/?enc=v0lIMeFN2TlPi5hBTQHY6A%3D%3D.fE3o%2FrvEosQP6ITgIJFJ%2FmLXHD1M%2FPTzaxUVvqwh%2BMpNSWTyrLsoPGHjvHSsnmd8BNN2b%2F3RVR6xE1P2z1Q9Hw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Spring Boot \u6838\u5fc3\u6280\u672f\u8bfe<\/a>\u300b\uff0c16 \u4e2a\u6a21\u5757\uff0c\u51e0\u4e4e\u6d89\u53ca\u6240\u6709\u6838\u5fc3\u6280\u672f\uff0c\u5305\u62ec\u5e95\u5c42\u5b9e\u73b0\u539f\u7406\u53ca\u4ee3\u7801\u5b9e\u6218\uff0c\u77e5\u8bc6\u70b9\u975e\u5e38\u9f50\u5168\uff0c\u52a9\u4f60\u5feb\u901f\u6253\u901a Spring Boot \u7684\u5404\u4e2a\u73af\u8282\u3002<\/p>\n<p>\u7b49\u66f4\u65b0\u5230 Spring Boot <strong>3.5<\/strong>+\uff0c\u672c\u8bfe\u7a0b\u4f1a\u6da8\u4ef7\u5230 <strong>499<\/strong> \u5143\uff0c\u65e9\u8ba2\u9605\uff0c\u65e9\u5b66\u4e60\uff0c\u65e9\u53d7\u76ca\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u4eca\u5929\u7684\u5206\u4eab\u5c31\u5230\u8fd9\u91cc\u4e86\uff0c\u540e\u7eedR\u54e5\u4e5f\u4f1a\u7ee7\u7eed\u5173\u6ce8\u5e76\u5206\u4eab\u66f4\u591a\u7684 Spring Boot \u8d44\u8baf\u548c\u5e72\u8d27\uff0c\u5173\u6ce8\u516c\u4f17\u53f7Java\u6280\u672f\u6808\u7b2c\u4e00\u65f6\u95f4\u63a8\u9001\u3002<\/p>\n<blockquote><p><strong>\u7248\u6743\u58f0\u660e\uff1a<\/strong> \u672c\u6587\u7cfb\u516c\u4f17\u53f7 &#8220;Java\u6280\u672f\u6808&#8221; \u539f\u521b\uff0c\u8f6c\u8f7d\u3001\u5f15\u7528\u672c\u6587\u5185\u5bb9\u8bf7\u6ce8\u660e\u51fa\u5904\uff0c\u6284\u88ad\u3001\u6d17\u7a3f\u4e00\u5f8b\u6295\u8bc9\u4fb5\u6743\uff0c\u540e\u679c\u81ea\u8d1f\uff0c\u5e76\u4fdd\u7559\u8ffd\u7a76\u5176\u6cd5\u5f8b\u8d23\u4efb\u7684\u6743\u5229\u3002<\/p><\/blockquote>\n<p><strong>\u66f4\u591a\u6587\u7ae0\u63a8\u8350\uff1a<\/strong><\/p>\n<p>1.<a href=\"https:\/\/link.segmentfault.com\/?enc=ks0rWqiP1%2Bc8YkKRxKAVlQ%3D%3D.NPb7Xt5%2FNYBdMxt9JhXxss%2BPW%2F1SE66SAs1YzzLxo%2FLtuV%2BDUNCLZhqyVBzJ7uYI\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Spring Boot 3.x \u6559\u7a0b\uff0c\u592a\u5168\u4e86\uff01<\/a><\/p>\n<p>2.<a href=\"https:\/\/link.segmentfault.com\/?enc=v%2Fv3D4q3rESkBeC6Gn30pQ%3D%3D.qbUVgeaRq2weEEsjosM%2BlvlXredvCTsHHEiqb01I6Yo%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">2,000+ \u9053 Java\u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406(2024\u6700\u65b0\u7248)<\/a><\/p>\n<p>3.<a href=\"https:\/\/link.segmentfault.com\/?enc=suJcmaK2%2FuY364XRBAWx8Q%3D%3D.7Pytip%2FovyVT0vYBBuJWBPdehTTvKIpnH91LN6oxjLs8KKa%2F2XXohkkyG4NB%2FKf9tl45WkV7kT88Gqz2DpmYdg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u514d\u8d39\u83b7\u53d6 IDEA \u6fc0\u6d3b\u7801\u7684 7 \u79cd\u65b9\u5f0f\uff082024\u6700\u65b0\u7248\uff09<\/a><\/p>\n<p>\u89c9\u5f97\u4e0d\u9519\uff0c\u522b\u5fd8\u4e86\u968f\u624b\u70b9\u8d5e+\u8f6c\u53d1\u54e6\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045508615\">https:\/\/segmentfault.com\/a\/1190000045508615<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662fR\u54e5\u3002 \u6700\u65b0\u6d88\u606f\uff0cSpring Boot \u4e00\u6b21\u6027\u53d1\u5e03\u4e86 6 \u4e2a\u7248\u672c\uff1a 3.4.0 3.3.6 3. [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020423","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020423"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020423\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}