{"id":747,"date":"2023-05-28T02:11:04","date_gmt":"2023-05-27T18:11:04","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=747"},"modified":"2023-05-28T02:11:04","modified_gmt":"2023-05-27T18:11:04","slug":"spring-profile%e6%b3%a8%e8%a7%a3%e4%bd%bf%e7%94%a8%e5%92%8c%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-profile%e6%b3%a8%e8%a7%a3%e4%bd%bf%e7%94%a8%e5%92%8c%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86%e8%a7%a3%e6%9e%90\/","title":{"rendered":"Spring @Profile\u6ce8\u89e3\u4f7f\u7528\u548c\u5b9e\u73b0\u539f\u7406\u89e3\u6790"},"content":{"rendered":"<div class='wxsyncmain'>\n<section><mp-common-profile class=\"js_uneditable custom_select_card mp_profile_iframe\" data-pluginname=\"mpprofile\" data-weui-theme=\"light\" data-id=\"MzI3ODE5MzczNA==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/OC2PjnBlMZjic6L6UHJXiaT0JCXiapkjUlh1wc5YRxBr1FvF4JB2kMibDia0m1vPHLtKr1BMxWm2QeGBRJhiaicbicw00w\/0?wx_fmt=png\" data-nickname=\"\u5218\u724c\" data-alias=\"\" data-signature=\"\u5bfb\u5e38\u7684\u74e6\u820d\u8bc4\u4e66\uff0c\u6697\u85cf\u7740\u6551\u4e16\u79d8\u8bc0\u3002\" data-from=\"0\" data-is_biz_ban=\"0\"><\/mp-common-profile><\/section>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"color: black;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-size: 16px;padding: 10px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;\">\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 20px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 8px solid #ffbf52;\">\u4ecb\u7ecd<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c\u5199\u4e86\u4e00\u7bc7\u4f7f\u7528Spring @Profile\u5b9e\u73b0\u5f00\u53d1\u73af\u5883\uff0c\u6d4b\u8bd5\u73af\u5883\uff0c\u751f\u4ea7\u73af\u5883\u7684\u5207\u6362\uff0c\u4e4b\u524d\u7684\u6587\u7ae0\u662f\u4f7f\u7528SpringBoot\u9879\u76ee\u642d\u5efa\uff0c\u5b9e\u73b0\u4e86\u4e0d\u540c\u73af\u5883\u6570\u636e\u6e90\u7684\u5207\u6362\uff0c\u5728\u6211\u4eec\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u4f1a\u5206\u4e3adev\uff0ctest\uff0cprod\u7b49\u73af\u5883\uff0c\u4ed6\u4eec\u4e4b\u95f4\u6570\u72ec\u7acb\u7684\uff0c\u4eca\u5929\u8fdb\u6765\u8be6\u89e3\u4ecb\u7ecdSpring @Profile\u7684\u539f\u7406\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\"><a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzI3ODE5MzczNA==&amp;mid=2247484263&amp;idx=1&amp;sn=adb2c38f9a57b5e9d009e0c0ba780621&amp;chksm=eb5bf04edc2c79585f25244502e8e81b3c3c2c16a932b6385a5631addc46787496829be632cf&amp;scene=21#wechat_redirect\" textvalue=\"Spring\u6ce8\u89e3@Profile\u5b9e\u73b0\u5f00\u53d1\u73af\u5883\uff0c\u6d4b\u8bd5\u73af\u5883\uff0c\u751f\u4ea7\u73af\u5883\u7684\u5207\u6362\" linktype=\"text\" imgurl=\"\" imgdata=\"null\" data-itemshowtype=\"0\" tab=\"innerlink\" data-linktype=\"2\" rel=\"noopener\" rel=\"nofollow\" >Spring\u6ce8\u89e3@Profile\u5b9e\u73b0\u5f00\u53d1\u73af\u5883\uff0c\u6d4b\u8bd5\u73af\u5883\uff0c\u751f\u4ea7\u73af\u5883\u7684\u5207\u6362<\/a><br  \/><\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 20px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 8px solid #ffbf52;\">\u4f7f\u7528<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u5e26\u6709@Profile\u7684\u6ce8\u89e3\u7684bean\u7684\u4e0d\u4f1a\u88ab\u6ce8\u518c\u8fdbIOC\u5bb9\u5668\uff0c\u9700\u8981\u4e3a\u5176\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6fc0\u6d3b\uff0c\u624d\u80fd\u6ce8\u518c\u8fdbIOC\u5bb9\u5668\uff0c\u5982\u4e0b\u901a\u8fc7setActiveProfiles\u8bbe\u7f6e\u4e86dev\u503c\uff0c\u90a3\u4e48\u8fd9\u4e09\u4e2a\u503c\u6240\u5bf9\u5e94\u7684Bean\u4f1a\u88ab\u6ce8\u518c\u8fdbIOC\u5bb9\u5668\u3002\u5f53\u7136\uff0c\u6211\u4eec\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u4e0d\u4f1a\u8fd9\u6837\u53bb\u505a\uff0c\u4f7f\u7528SpringBoot\u7684\u8bdd\uff0c\u6211\u4eec\u4e00\u822c\u662f\u4f7f\u7528yml\uff0c\u5728yml\u4e2d\u914d\u7f6e<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(244, 138, 0);\">spring.profiles.active<\/code>\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6ejvm\u53c2\u6570\u3002<\/p>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 20px;margin-top: 15px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 18px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 4px solid #ffe3a3;\">\u901a\u8fc7Environment\u8bbe\u7f6eprofile<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7Environment\u6765\u8bbe\u7f6e\u73af\u5883\u5c5e\u6027\uff0c\u8fd9\u662f\u6bd4\u8f83\u539f\u751f\u7684\u65b9\u6cd5\u3002<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background: url(&quot;https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015826483.jpeg&quot;) 10px 10px \/ 40px no-repeat rgb(40, 44, 52);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;\"><\/span><code style=\"overflow-x: auto;padding: 16px;color: #abb2bf;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #282c34;border-radius: 5px;\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: #c678dd;line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">boolean<\/span>&nbsp;<span style=\"color: #61aeee;line-height: 26px;\">matches<\/span><span style=\"line-height: 26px;\">(ConditionContext&nbsp;context,&nbsp;AnnotatedTypeMetadata&nbsp;metadata)<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultiValueMap&lt;String,&nbsp;Object&gt;&nbsp;attrs&nbsp;=&nbsp;metadata.getAllAnnotationAttributes(Profile<span style=\"line-height: 26px;\">.<span style=\"color: #c678dd;line-height: 26px;\">class<\/span>.<span style=\"color: #e6c07b;line-height: 26px;\">getName<\/span>())<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(attrs&nbsp;!=&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">null<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">for<\/span>&nbsp;(Object&nbsp;value&nbsp;:&nbsp;attrs.get(<span style=\"color: #98c379;line-height: 26px;\">\"value\"<\/span>))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(context.getEnvironment().acceptsProfiles(Profiles.of((String[])&nbsp;value)))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">return<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">true<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">return<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">false<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">return<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">true<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u4ece\u6e90\u7801\u53ef\u4ee5\u770b\u51fa\uff0c\u5176\u6700\u6838\u5fc3\u7684\u601d\u60f3\u5c31\u662f\u662f\u5426\u6ce8\u518cbean\u7684\u5143\u4fe1\u606fBeanDefinition\uff0c\u56e0\u4e3a\u53ea\u6709\u6ce8\u518c\u4e86BeanDefinition\uff0c\u540e\u7eed\u624d\u80fd\u4e3a\u521b\u5efabean\u63d0\u4f9b\u5143\u6570\u636e\u652f\u6301\uff0c\u5224\u65ad\u662f\u5426\u6ce8\u518cbean\u5143\u4fe1\u606f\uff0c\u4e3b\u8981\u5c31\u662f\u4eceEnvironment\u4e2d\u53d6\u51faprofiles\u7684\u503c\uff0c\u7136\u540e\u548c@Profile\u6ce8\u89e3\u8bbe\u7f6e\u7684\u503c\u8fdb\u884c\u5339\u914d\uff0c\u5339\u914d\u5f97\u4e0a\u5c31\u6ce8\u518c\uff0cbean\u4e0d\u4e0a\u5c31\u4e0d\u6ce8\u518c\u3002<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 20px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 8px solid #ffbf52;\">\u603b\u7ed3<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u4e0a\u9762\u6211\u4eec\u5bf9@Profile\u7684\u4f7f\u7528\u505a\u4e86\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u5e76\u5bf9\u5b83\u7684\u6838\u5fc3\u6e90\u7801\u8fdb\u884c\u89e3\u5256\uff0c\u65e0\u975e\u5c31\u662f\u5224\u65ad\u662f\u5426\u8981\u6ce8\u518cBeanDefinition\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u505a\u4e00\u4e9b\u73af\u5883\u9694\u79bb\u7684\u5de5\u4f5c\uff0c\u4f7f\u7528@Profile\u8fd8\u662f\u6bd4\u8f83\u4e0d\u9519\u7684\u3002<\/p>\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 0.9em;overflow: auto;color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;text-size-adjust: 100%;line-height: 1.75em;border-radius: 5px;box-sizing: inherit;border-width: 1px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-color: rgb(255, 191, 82);background: rgb(255, 248, 230);\"><p><span style=\"color: #f48a00;font-size: 32px;line-height: 0.6;margin-left: -15px;\">\u275d<\/span><\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;letter-spacing: 0.1em;font-size: 16px;word-spacing: 0.1em;text-align: justify;line-height: 26px;margin-top: -15px;color: rgba(0, 0, 0, 0.85);\">\u4eca\u5929\u7684\u5206\u4eab\u5c31\u5230\u8fd9\u91cc\uff0c\u611f\u8c22\u4f60\u7684\u89c2\u770b\uff0c\u4e0b\u671f\u89c1\uff01<\/p>\n<\/blockquote>\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:                 \u5218\u724c              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd \u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c\u5199\u4e86\u4e00\u7bc7\u4f7f\u7528Spring @Profile\u5b9e\u73b0\u5f00\u53d1\u73af\u5883\uff0c\u6d4b\u8bd5\u73af\u5883\uff0c\u751f\u4ea7\u73af\u5883\u7684\u5207\u6362\uff0c\u4e4b\u524d\u7684\u6587\u7ae0\u662f\u4f7f\u7528Sprin &#8230;<\/p>\n","protected":false},"author":2,"featured_media":743,"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-747","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442-300x127.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442-300x127.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015823442.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","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":326,"next_post_id":1005,"next_post_title":"\u6570\u636e\u5e93\u94fe\u63a5\u6c60\u7ec8\u4e8e\u641e\u5bf9\u4e86\uff0c\u8fd9\u6b21\u76f4\u63a5\u4ece100ms\u4f18\u5316\u52303ms\uff01","previous_post_id":917,"previous_post_title":"Spring-15 Spring Certified Professional \u8bd5\u9898\u6574\u7406 \u2460","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/747","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=747"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/747\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/743"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}