{"id":1237,"date":"2023-05-28T04:10:16","date_gmt":"2023-05-27T20:10:16","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=1237"},"modified":"2023-05-28T04:10:16","modified_gmt":"2023-05-27T20:10:16","slug":"%e3%80%90spring%e6%89%a9%e5%b1%95%e7%82%b9%e3%80%91-%e5%ae%b9%e5%99%a8%e5%88%b7%e6%96%b0%e5%89%8d%e5%9b%9e%e8%b0%83applicationcontextinitializer","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring\/%e3%80%90spring%e6%89%a9%e5%b1%95%e7%82%b9%e3%80%91-%e5%ae%b9%e5%99%a8%e5%88%b7%e6%96%b0%e5%89%8d%e5%9b%9e%e8%b0%83applicationcontextinitializer\/","title":{"rendered":"\u3010Spring\u6269\u5c55\u70b9\u3011 \u5bb9\u5668\u5237\u65b0\u524d\u56de\u8c03ApplicationContextInitializer"},"content":{"rendered":"<div class='wxsyncmain'>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"font-size: 16px;color: black;padding-right: 10px;padding-left: 10px;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;\">\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"border-top: none;border-right: none;border-bottom: none;font-size: 0.9em;overflow: auto;color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;border-left-color: rgb(239, 112, 96);background: rgb(255, 249, 249);\">\n<p style=\"font-size: 16px;padding-top: 8px;padding-bottom: 8px;color: black;line-height: 26px;\">\u3010Spring\u6269\u5c55\u70b9\u3011 \u5bb9\u5668\u5237\u65b0\u524d\u56de\u8c03ApplicationContextInitializer<\/p>\n<\/blockquote>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.3333333333333333\"  data-type=\"jpeg\" data-w=\"960\" style=\"display: block;margin-right: auto;margin-left: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.3333333333333333\"  data-type=\"jpeg\" data-w=\"960\" style=\"display: block;margin-right: auto;margin-left: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg\"><\/noscript><\/figure>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u672c\u6587\u5c06\u4f5c\u4e3aSpring\u7cfb\u5217\u6559\u7a0b\u4e2d\u6e90\u7801\u7248\u5757\u7684\u7b2c\u4e00\u7bc7\uff0c\u6574\u4e2a\u6e90\u7801\u7cfb\u5217\u5c06\u5206\u4e3a\u4e24\u90e8\u5206\u8fdb\u884c\u4ecb\u7ecd\uff1b\u5355\u7eaf\u7684\u6e90\u7801\u89e3\u6790\uff0c\u5927\u6982\u7387\u662f\u4e2a\u5403\u529b\u6ca1\u4eba\u770b\u7684\u4e8b\u60c5\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u7ed3\u5408\u6e90\u7801\u89e3\u6790\uff0c\u4e00\u4e2a\u662f\u5b66\u4e60\u4e0b\u522b\u4eba\u7684\u4f18\u79c0\u8bbe\u8ba1\uff0c\u4e00\u4e2a\u662f\u7ad9\u5728\u6e90\u7801\u7684\u89d2\u5ea6\u770b\u4e00\u4e0b\u6211\u4eec\u9664\u4e86\u65e5\u5e38\u7684CURD\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u5e72\u4e9b\u5565<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5728Spring\u7684\u542f\u52a8\u8fc7\u7a0b\u4e2d\uff0c\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\u6b65\u9aa4\u4e2d\uff0c\u63d0\u4f9b\u4e86\u5f88\u591a\u7684\u6269\u5c55\u70b9\uff0c\u4f9b\u6211\u4eec\u6765\u589e\u5f3a\uff1b\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u63d0\u4f9b\u4e86\u5f88\u591a\u7684\u94a9\u5b50\uff0c\u8fd9\u6837\u5f53\u6211\u4eec\u5728\u67d0\u4e2a\u8282\u70b9\u6267\u884c\u524d\u540e\uff0c\u60f3\u5e72\u70b9\u5176\u4ed6\u7684\u4e8b\u60c5\u65f6\uff0c\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u652f\u6301\uff1b\u672c\u6587\u4ecb\u7ecd\u7684<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">ApplicationContextInitializer<\/code>\uff0cspring\u5bb9\u5668\u5728\u5237\u65b0\u4e4b\u524d\u4f1a\u56de\u8c03\u8fd9\u4e2a\u63a5\u53e3\uff0c\u4ece\u800c\u5b9e\u73b0\u5728spring\u5bb9\u5668\u672a\u521d\u59cb\u5316\u524d\uff0c\u5e72\u4e00\u4e9b\u7528\u6237\u5e0c\u671b\u505a\u7684\u4e8b\u60c5<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;border-bottom: 2px solid rgb(239, 112, 96);font-size: 1.3em;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"display: inline-block;padding: 3px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px;\">I. \u9879\u76ee\u51c6\u5907<\/span><span><\/span><span style=\"display: inline-block;vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent;\"> <\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u672c\u6587\u521b\u5efa\u7684\u5b9e\u4f8b\u5de5\u7a0b\u91c7\u7528<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">SpringBoot 2.2.1.RELEASE<\/code> + <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">maven 3.5.3<\/code> + <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">idea<\/code>\u8fdb\u884c\u5f00\u53d1<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5177\u4f53\u7684SpringBoot\u9879\u76ee\u5de5\u7a0b\u521b\u5efa\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u6838\u5fc3\u7684pom\u6587\u4ef6\uff0c\u65e0\u9700\u989d\u5916\u7684\u4f9d\u8d56<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u914d\u7f6e\u6587\u4ef6 <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">application.yml<\/code>\uff0c \u4e5f\u6ca1\u6709\u4ec0\u4e48\u7279\u6b8a\u7684\u914d\u7f6e<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u6e90\u7801\u5de5\u7a0b\u53c2\u8003\u6587\u672b\u7684\u6e90\u7801<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;border-bottom: 2px solid rgb(239, 112, 96);font-size: 1.3em;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"display: inline-block;padding: 3px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px;\">II. \u5bb9\u5668\u5237\u65b0\u524d\u6269\u5c55\u70b9\u5b9e\u4f8b<\/span><span><\/span><span style=\"display: inline-block;vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent;\"> <\/span><\/h2>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">1. \u81ea\u5b9a\u4e49ApplicationContextInitializer<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5f53\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u4e0a\u4e0b\u6587\u521d\u59cb\u5316\u65f6\uff0c\u975e\u5e38\u7b80\u5355\uff0c\u5b9e\u73b0\u4e0a\u9762\u8fd9\u4e2a\u63a5\u53e3\u5c31\u884c\u4e86\uff0c\u5982<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer01<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span style=\"color: #d14;line-height: 26px;\">\"ApplicationContextInitializer01\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">2. \u6269\u5c55\u70b9\u6ce8\u518c<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e0a\u9762\u81ea\u5b9a\u4e49\u4e00\u4e2a\u6269\u5c55\u70b9\uff0c\u5982\u4f55\u4f7f\u5b83\u751f\u6548\u5462\uff1f<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5b98\u65b9\u63d0\u4f9b\u4e86\u4e09\u79cd\u65b9\u5f0f\uff0c\u5982\u5728\u542f\u52a8\u65f6\uff0c\u76f4\u63a5\u8fdb\u884c\u6ce8\u518c: <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">springApplication.addInitializers(new ApplicationContextInitializer01());<\/code><\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"color: #999;font-weight: bold;line-height: 26px;\">@SpringBootApplication<\/span><br  \/><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">Application<\/span>&nbsp;<\/span>{<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">static<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">main<\/span><span style=\"line-height: 26px;\">(String[]&nbsp;args)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SpringApplication&nbsp;springApplication&nbsp;=&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;SpringApplication(Application<span style=\"line-height: 26px;\">.<span style=\"font-weight: bold;line-height: 26px;\">class<\/span>)<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;springApplication.addInitializers(<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;ApplicationContextInitializer01());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">try<\/span>&nbsp;(ConfigurableApplicationContext&nbsp;context&nbsp;=&nbsp;springApplication.run(args))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5f53\u6211\u4eec\u7684\u6269\u5c55\u70b9\u662f\u653e\u5728\u4e00\u4e2ajar\u5305\u4e2d\u5bf9\u5916\u63d0\u4f9b\u65f6\uff0c\u4f7f\u7528\u4e0a\u9762\u7684\u542f\u52a8\u6ce8\u518c\u65b9\u5f0f\u663e\u7136\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u6b64\u65f6\u66f4\u63a8\u8350\u7684\u505a\u6cd5\u5c31\u662f\u901a\u8fc7Spring\u7684SPI\u673a\u5236\u8fdb\u884c\u6ce8\u518c<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5728\u8d44\u6e90\u76ee\u5f55\u4e0b\u7684<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">META-INF\/spring.factories<\/code>\u6587\u4ef6\u4e2d\u8fdb\u884c\u6ce8\u518c<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\">org.springframework.context.ApplicationContextInitializer=com.git.hui.extention.context.ApplicationContextInitializer02<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\"><strong>\u8bf4\u660e<\/strong><\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u4e0a\u9762SPI\u7684\u673a\u5236\u975e\u5e38\u63a8\u8350\u5927\u5bb6\u4f7f\u7528\uff0c\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">AutoConfiguration<\/code>\u7684\u6ce8\u518c\u901a\u5e38\u4e5f\u662f\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f<\/section>\n<\/li>\n<\/ul>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u9664\u4e86\u4e0a\u9762\u7684\u4e24\u79cd\u6ce8\u518c\u65b9\u5f0f\u4e4b\u5916\uff0c\u53e6\u5916\u8fd8\u6709\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5728\u914d\u7f6e\u6587\u4ef6<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">application.properties<\/code> \u6216 <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">application.yml<\/code>\u4e2d\uff0c\u5982\u4e0b\u914d\u7f6e<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"line-height: 26px;\">context:<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\">initializer:<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\">classes:<\/span>&nbsp;<span style=\"color: #d14;line-height: 26px;\">com.git.hui.extention.context.ApplicationContextInitializer03<\/span><br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\"><strong>\u542f\u52a8\u6d4b\u8bd5<\/strong><\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e0a\u9762\u4e09\u79cd\u6ce8\u518c\u65b9\u5f0f\uff0c\u6211\u4eec\u5b9e\u73b0\u4e09\u4e2a\u81ea\u5b9a\u4e49\u7684\u6269\u5c55\u70b9\uff0c\u7136\u540e\u542f\u52a8\u4e4b\u540e\uff0c\u770b\u4e00\u4e0b\u5b9e\u9645\u8f93\u51fa<\/p>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.2808080808080808\"  data-type=\"jpeg\" data-w=\"990\" style=\"display: block;margin-right: auto;margin-left: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040623997.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.2808080808080808\"  data-type=\"jpeg\" data-w=\"990\" style=\"display: block;margin-right: auto;margin-left: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040623997.jpeg\"><\/noscript><\/figure>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e0a\u9762\u7684\u8f93\u51fa\uff0c\u53ef\u4ee5\u7b80\u5355\u7684\u5f97\u51fa\u4e00\u4e2a\u7ed3\u8bba\uff0c\u4e0d\u540c\u6ce8\u518c\u65b9\u5f0f\u7684\u4f18\u5148\u7ea7\uff08\u4e3a\u4e86\u66f4\u5408\u7406\u7684\u9a8c\u8bc1\u4e0b\u9762\u7684\u89c2\u70b9\uff0c\u63a8\u8350\u5927\u5bb6\u4fee\u6539\u4e0b\u4e0a\u9762\u4e09\u4e2a\u81ea\u5b9a\u4e49\u6269\u5c55\u70b9\u540d\uff0c\u6392\u9664\u6389\u662f\u56e0\u4e3a\u6269\u5c55\u540d\u5bfc\u81f4\u7684\u6392\u5e8f\u95ee\u9898\uff09<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u914d\u7f6e\u6587\u4ef6\u6ce8\u518c &gt; SPI\u6ce8\u518c &gt; \u542f\u52a8\u65f6\u6ce8\u518c<\/section>\n<\/li>\n<\/ul>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">3. \u6267\u884c\u987a\u5e8f\u6307\u5b9a<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u7684\u6269\u5c55\u70b9\u5b9e\u73b0\uff0c\u5f53\u5b58\u5728\u987a\u5e8f\u5173\u7cfb\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">@Order<\/code>\u6ce8\u89e3\u6765\u5b9e\u73b0\uff0c \u5982\u5f53\u4e0a\u9762\u7684\u4e09\u4e2a\u6269\u5c55\u70b9\u90fd\u662f\u901a\u8fc7\u542f\u52a8\u65b9\u5f0f\u6ce8\u518c\u65f6<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Order<\/span>(<span style=\"color: #008080;line-height: 26px;\">5<\/span>)<br  \/><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer01<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span style=\"color: #d14;line-height: 26px;\">\"ApplicationContextInitializer01\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><br  \/><span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Order<\/span>(<span style=\"color: #008080;line-height: 26px;\">2<\/span>)<br  \/><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer02<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span style=\"color: #d14;line-height: 26px;\">\"ApplicationContextInitializer02\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><br  \/><span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Order<\/span>(<span style=\"color: #008080;line-height: 26px;\">10<\/span>)<br  \/><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer03<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span style=\"color: #d14;line-height: 26px;\">\"ApplicationContextInitializer03\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><br  \/><span style=\"color: #999;font-weight: bold;line-height: 26px;\">@SpringBootApplication<\/span><br  \/><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">Application<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">static<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">main<\/span><span style=\"line-height: 26px;\">(String[]&nbsp;args)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SpringApplication&nbsp;springApplication&nbsp;=&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;SpringApplication(Application<span style=\"line-height: 26px;\">.<span style=\"font-weight: bold;line-height: 26px;\">class<\/span>)<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;springApplication.addInitializers(<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;ApplicationContextInitializer01(),&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;ApplicationContextInitializer02(),&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;ApplicationContextInitializer03());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">try<\/span>&nbsp;(ConfigurableApplicationContext&nbsp;context&nbsp;=&nbsp;springApplication.run(args))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u8f93\u51fa\u5b9e\u4f8b\u5982\u4e0b<\/p>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.23153942428035043\"  data-type=\"jpeg\" data-w=\"799\" style=\"display: block;margin-right: auto;margin-left: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040624943.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.23153942428035043\"  data-type=\"jpeg\" data-w=\"799\" style=\"display: block;margin-right: auto;margin-left: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040624943.jpeg\"><\/noscript><\/figure>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\"><strong>\u63a5\u7740\u91cd\u70b9\u6765\u4e86<\/strong><\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u82e5\u4e0a\u9762\u7684\u4e09\u4e2a\u81ea\u5b9a\u4e49\u5b9e\u73b0\uff0c\u4e0d\u662f\u76f8\u540c\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u5982\u5c0603\u91c7\u7528\u914d\u7f6e\u6587\u4ef6\u65b9\u5f0f\u8fdb\u884c\u6ce8\u518c\uff0c\u90a3\u4e4801, 02 \u4f9d\u7136\u662f\u542f\u52a8\u6ce8\u518c<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5219\u987a\u5e8f\u662f 03 &gt; 02 &gt; 01<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5373 <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">@Order<\/code>\u6ce8\u89e3\u4fee\u9970\u7684\u987a\u5e8f\uff0c\u5e76\u4e0d\u80fd\u6253\u7834 &nbsp;<strong style=\"color: black;\">\u914d\u7f6e\u6587\u4ef6 &gt; SPI &gt; \u542f\u52a8\u65b9\u5f0f\u6ce8\u518c\u7684\u987a\u5e8f<\/strong><\/section>\n<\/li>\n<\/ul>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5173\u4e8e\u81ea\u5b9a\u4e49\u5b9e\u73b0\u7c7b\u7684\u6267\u884c\u987a\u5e8f\uff0c\u89c4\u5219\u5982\u4e0b<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u914d\u7f6e\u6587\u4ef6 &gt; SPI &gt; \u542f\u52a8\u65b9\u5f0f<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u76f8\u540c\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u53ef\u4ee5\u901a\u8fc7 <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">@Order<\/code> \u6ce8\u89e3\u8fdb\u884c\u4fee\u9970\uff0c\u503c\u8d8a\u5c0f\u5219\u4f18\u5148\u7ea7\u8d8a\u9ad8<\/section>\n<\/li>\n<\/ul>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">4. \u4f7f\u7528\u573a\u666f\u793a\u4f8b<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u6700\u540e\u6211\u4eec\u518d\u6765\u770b\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u6269\u5c55\u70b9\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff0c\u6211\u4eec\u518d\u4ec0\u4e48\u573a\u666f\u4e0b\u4f1a\u7528\u5230\u8fd9\u4e2a\u5462\uff1f<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e00\u4e2a\u7ecf\u5e38\u53ef\u4ee5\u770b\u5230\u7684\u5e94\u7528\u573a\u666f\u5982\u901a\u8fc7\u5b83\u6765\u6307\u5b9a\u9700\u8981\u6fc0\u6d3b\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer03<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #998;font-style: italic;line-height: 26px;\">\/\/&nbsp;\u6307\u5b9a\u6fc0\u6d3bprod\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configurableApplicationContext.getEnvironment().setActiveProfiles(<span style=\"color: #d14;line-height: 26px;\">\"prod\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4f46\u662f\u4e00\u822c\u4e5f\u5f88\u5c11\u89c1\u5230\u6709\u4eba\u8fd9\u4e48\u5e72\uff0c\u56e0\u4e3a\u76f4\u63a5\u4f7f\u7528\u914d\u7f6e\u53c2\u6570\u5c31\u884c\u4e86\uff0c\u90a3\u4e48\u6709\u573a\u666f\u9700\u8981\u8fd9\u4e48\u505a\u4e48\uff1f<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u7b54\u6848\u5f53\u7136\u662f\u6709\u7684\uff0c\u6bd4\u5982\u73b0\u5728\u5e7f\u4e3a\u6d41\u884c\u7684docker\u5bb9\u5668\u90e8\u7f72\uff0c\u5f53\u6211\u4eec\u5e0c\u671b\u6bcf\u6b21\u90fd\u662f\u6253\u540c\u4e00\u4e2a\u955c\u50cf\uff0c\u7136\u540e\u5728\u5b9e\u9645\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u6839\u636e\u4e0d\u540c\u7684\u73af\u5883\u6765\u51b3\u5b9a\u5f53\u524d\u955c\u50cf\u5230\u5e95\u542f\u7528\u54ea\u4e9b\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u65f6\u5c31\u6709\u7528\u4e86<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u6bd4\u5982\u6211\u4eec\u901a\u8fc7\u5bb9\u5668\u7684\u73af\u5883\u53c2\u6570 <code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">app.env<\/code> \u6765\u83b7\u53d6\u5f53\u524d\u8fd0\u884c\u7684\u73af\u5883\uff0c\u5982\u679c\u662fprod\uff0c\u5219\u6fc0\u6d3b<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">application-prod.yml<\/code>; \u5982\u679c\u662ftest\uff0c\u5219\u6fc0\u6d3b<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">application-test.yml<\/code><\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u90a3\u4e48\u6b64\u65f6\u53ef\u4ee5\u8fd9\u4e48\u5e72<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;\"><code style=\"overflow-x: auto;padding: 16px;color: #333;background: #f8f8f8;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;border-radius: 0px;font-size: 12px;-webkit-overflow-scrolling: touch;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">EenvActiveApplicationContextInitializer<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: #458;font-weight: bold;line-height: 26px;\">ApplicationContextInitializer<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #999;font-weight: bold;line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"font-weight: bold;line-height: 26px;\">public<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: #900;font-weight: bold;line-height: 26px;\">initialize<\/span><span style=\"line-height: 26px;\">(ConfigurableApplicationContext&nbsp;configurableApplicationContext)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;env&nbsp;=&nbsp;System.getenv(<span style=\"color: #d14;line-height: 26px;\">\"app.env\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">if<\/span>&nbsp;(<span style=\"color: #d14;line-height: 26px;\">\"prod\"<\/span>.equalsIgnoreCase(env))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configurableApplicationContext.getEnvironment().setActiveProfiles(<span style=\"color: #d14;line-height: 26px;\">\"prod\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">else<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">if<\/span>&nbsp;(<span style=\"color: #d14;line-height: 26px;\">\"test\"<\/span>.equalsIgnoreCase(env))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configurableApplicationContext.getEnvironment().setActiveProfiles(<span style=\"color: #d14;line-height: 26px;\">\"test\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">else<\/span>&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">throw<\/span>&nbsp;<span style=\"font-weight: bold;line-height: 26px;\">new<\/span>&nbsp;RuntimeException(<span style=\"color: #d14;line-height: 26px;\">\"\u975e\u6cd5\u7684\u73af\u5883\u53c2\u6570\uff1a\"<\/span>&nbsp;+&nbsp;env);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">5. \u5c0f\u7ed3<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u672c\u6587\u4f5c\u4e3a\u6269\u5c55\u70b9\u7684\u7b2c\u4e00\u7bc7\uff0c\u901a\u8fc7\u5b9e\u73b0<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">ApplicationContextInitializer<\/code>\u63a5\u53e3\uff0c\u4ece\u800c\u8fbe\u5230\u5728spring\u5bb9\u5668\u5237\u65b0\u4e4b\u524d\u505a\u67d0\u4e9b\u4e8b\u60c5\u7684\u76ee\u7684<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u901a\u5e38\u81ea\u5b9a\u4e49\u7684ApplicationContextInitializer\u6709\u4e09\u79cd\u6ce8\u518c\u65b9\u5f0f\uff0c\u6309\u7167\u4f18\u5148\u7ea7\u5982\u4e0b<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u914d\u7f6e\u6587\u4ef6 &gt; SPI\u65b9\u5f0f &gt; \u542f\u52a8\u65b9\u5f0f\u6ce8\u518c<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u76f8\u540c\u7684\u6ce8\u518c\u65b9\u5f0f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">@Order<\/code>\u6ce8\u89e3\u6765\u6307\u5b9a\u4f18\u5148\u7ea7\uff0c\u503c\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8<\/section>\n<\/li>\n<\/ul>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u6700\u540e\u8fd8\u7ed9\u51fa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u5e94\u7528\u5f97\u5b9e\u4f8b\u573a\u666f\uff0c\u5373\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2a\u955c\u50cf\u5728\u4e0d\u540c\u7684\u73af\u5883\u4e2d\u542f\u52a8\u8fd0\u884c<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e0b\u4e00\u4e2a\u6269\u5c55\u70b9\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7<code style=\"font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);\">BeanDefinitionRegistryPostProcessor<\/code>\u6765\u5b9e\u73b0\u975eSpring\u751f\u6001\u7684Bean\u52a0\u8f7d\u4f7f\u7528<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;border-bottom: 2px solid rgb(239, 112, 96);font-size: 1.3em;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"display: inline-block;padding: 3px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px;\">III. \u4e0d\u80fd\u9519\u8fc7\u7684\u6e90\u7801\u548c\u76f8\u5173\u77e5\u8bc6\u70b9<\/span><span><\/span><span style=\"display: inline-block;vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent;\"> <\/span><\/h2>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">0. \u9879\u76ee<\/span><span style=\"display: none;\"><\/span><\/h3>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u5de5\u7a0b\uff1ahttps:\/\/github.com\/liuyueyi\/spring-boot-demo<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u6e90\u7801\uff1ahttps:\/\/github.com\/liuyueyi\/spring-boot-demo\/tree\/master\/spring-boot\/<\/section>\n<\/li>\n<\/ul>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 20px;\"><span style=\"display: none;\"><\/span><span style=\"border-left: 4px solid rgb(248,57,41);padding-left: 8px;\">1. \u5fae\u4fe1\u516c\u4f17\u53f7: \u4e00\u7070\u7070Blog<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u5c3d\u4fe1\u4e66\u5219\u4e0d\u5982\uff0c\u4ee5\u4e0a\u5185\u5bb9\uff0c\u7eaf\u5c5e\u4e00\u5bb6\u4e4b\u8a00\uff0c\u56e0\u4e2a\u4eba\u80fd\u529b\u6709\u9650\uff0c\u96be\u514d\u6709\u758f\u6f0f\u548c\u9519\u8bef\u4e4b\u5904\uff0c\u5982\u53d1\u73b0bug\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\uff0c\u6b22\u8fce\u6279\u8bc4\u6307\u6b63\uff0c\u4e0d\u541d\u611f\u6fc0<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;\">\u4e0b\u9762\u4e00\u7070\u7070\u7684\u4e2a\u4eba\u535a\u5ba2\uff0c\u8bb0\u5f55\u6240\u6709\u5b66\u4e60\u548c\u5de5\u4f5c\u4e2d\u7684\u535a\u6587\uff0c\u6b22\u8fce\u5927\u5bb6\u524d\u53bb\u901b\u901b<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u4e00\u7070\u7070Blog\u4e2a\u4eba\u535a\u5ba2 https:\/\/blog.hhui.top<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);\">\u4e00\u7070\u7070Blog-Spring\u4e13\u9898\u535a\u5ba2 http:\/\/spring.hhui.top<\/section>\n<\/li>\n<\/ul>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.4265791632485644\"  data-type=\"jpeg\" data-w=\"1219\" style=\"display: block;margin-right: auto;margin-left: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040625549.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.4265791632485644\"  data-type=\"jpeg\" data-w=\"1219\" style=\"display: block;margin-right: auto;margin-left: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040625549.jpeg\"><\/noscript><figcaption style=\"margin-top: 5px;text-align: center;color: #888;font-size: 14px;\">\u4e00\u7070\u7070blog<\/figcaption><\/figure>\n<\/section>\n<p><br  \/><\/p>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 \u4e00\u7070\u7070blog              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u3010Spring\u6269\u5c55\u70b9\u3011 \u5bb9\u5668\u5237\u65b0\u524d\u56de\u8c03ApplicationContextInitializer \u672c\u6587\u5c06\u4f5c\u4e3aSpring\u7cfb\u5217\u6559\u7a0b\u4e2d &#8230;<\/p>\n","protected":false},"author":1,"featured_media":1232,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[6,19],"tags":[],"class_list":["post-1237","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring","category-19"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755-300x127.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755-300x127.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040621755.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040622134.jpeg","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040623997.jpeg","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040623997.jpeg","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040624943.jpeg","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040624943.jpeg","id":"image5"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040625549.jpeg","id":"image6"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528040625549.jpeg","id":"image7"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring","post_date":"2023-05-27","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":298,"next_post_id":1974,"next_post_title":"Spring IoC\u901a\u4fd7\u7684\u89e3\u91ca","previous_post_id":1153,"previous_post_title":"\u5229\u7528Spring\u6269\u5c55\u70b9\u6a21\u62dfFeign\u5b9e\u73b0\u8fdc\u7a0b\u8c03\u7528","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1237","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=1237"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1237\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/1232"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}