{"id":9242,"date":"2023-02-02T16:56:19","date_gmt":"2023-02-02T08:56:19","guid":{"rendered":"http:\/\/123.57.164.21\/?p=9242"},"modified":"2023-02-02T16:56:19","modified_gmt":"2023-02-02T08:56:19","slug":"spring-profile-%e9%85%8d%e7%bd%ae%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=9242","title":{"rendered":"Spring.profile \u914d\u7f6e\u8be6\u89e3"},"content":{"rendered":"\n<p><strong>spring.profiles\u914d\u7f6e\u6587\u4ef6 \u8be6\u89e3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<ul><li>spring.profiles<\/li><li>spring.profiles.active<\/li><li>spring.profiles.include<\/li><\/ul>\n\n\n\n<p><strong><a rel=\"noreferrer noopener\" target=\"_blank\"><\/a>\u6b63\u5e38\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u6211\u4eec\u6b63\u5e38\u7684\u5f00\u53d1\u65f6\uff0c\u5bf9\u5e94\u4e0d\u540c\u7684\u73af\u5883\u6211\u4eec\u4f1a\u6709\u4e0d\u540c\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n\n\n\n<ul><li>application.yaml \u9ed8\u8ba4\u7684yaml\u6587\u4ef6<\/li><li>application-dev.yaml<\/li><li>application-test.yaml<\/li><li>application-prod.yaml<\/li><\/ul>\n\n\n\n<p>\u5e38\u89c4\u914d\u7f6e\u6587\u4ef6\u5982\u4e0a\uff0c\u4e00\u822c\u662f\u6309\u7167application-{\u73af\u5883}.yaml\u7684\u683c\u5f0f\u547d\u540d\uff0c\u5982\u679c\u9700\u8981\u53ef\u4ee5\u7ee7\u7eed\u4eff\u7167\u8fd9\u6837\u7684\u547d\u540d\u8fdb\u884c\u6dfb\u52a0\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u800c\u5728\u6211\u4eec\u4f7f\u7528\u7684\u65f6\u5019\uff1a<\/p>\n\n\n\n<ul><li>1.application.yaml\u4e2d\u6dfb\u52a0 spring.profiles.active={\u73af\u5883}<\/li><li>2.\u53ef\u4ee5\u8fd9\u6837\u901a\u8fc7\u5728\u542f\u52a8\u547d\u4ee4\u4e2d\u6dfb\u52a0\u5982\u4e0b\u547d\u4ee4<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">java -Dspring.profiles.active={\u73af\u5883} -jar ***.jar<\/pre>\n\n\n\n<ul><li>\u5982\u679c1\u548c2\u540c\u65f6\u8bbe\u5b9a\uff0c2\u4f1a\u8986\u76d61.\u542f\u52a82\u7684\u914d\u7f6e\u3002<\/li><\/ul>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u5728application.yaml\u4e2d\u914d\u7f6e\u4f1a\u751f\u6548\uff0c\u800c\u5728\u53e6\u5916\u4e09\u4e2a\u4e0d\u751f\u6548\uff1f<br>\u8fd9\u5c31\u7275\u6d89\u5230\uff0capplication.yaml\u7684\u7ee7\u627f\u4f5c\u7528\uff0c\u4e5f\u5c31\u662f\u8bf4\u65e0\u8bba\u662f\u542f\u52a8dev\uff0ctest\uff0cprod\uff0c\u90fd\u4f1a\u9ed8\u8ba4\u542f\u52a8application.yaml\u914d\u7f6e.<br>\u5982\u679c\u542f\u52a8dev\u73af\u5883\uff0c\u76f8\u5f53\u4e8e\u542f\u52a8\u4e86application-dev.yaml\u548capplication.yaml\u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u5e76\u96c6\uff0c\u76f8\u540c\u7684\u5c5e\u6027\uff0c\u5219\u4ee5dev\u914d\u7f6e\u6587\u4ef6\u4e3a\u4e3b\u3002\u76f8\u5f53\u4e8eapplication-dev.yaml\u7ee7\u627f\u4e86application.yaml\u3002<\/p>\n\n\n\n<p><strong><a rel=\"noreferrer noopener\" target=\"_blank\"><\/a>spring.profiles<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u65e2\u8981\u533a\u5206\u4e0d\u540c\u7684\u73af\u5883\uff0c\u4f46\u662f\u53c8\u8981\u5199\u5728\u4e00\u4e2a\u914d\u7f6e\u91cc\u9762\uff0c\u5c31\u4f1a\u9700\u8981\u8fd9\u4e2a\u5c5e\u6027\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/image-31-1024x519.png\" alt=\"\" class=\"wp-image-9243\" width=\"570\" height=\"288\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-1024x519.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-300x152.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-768x389.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-1536x779.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-830x421.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-230x117.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-350x177.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31-480x243.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-31.png 1688w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure><\/div>\n\n\n\n<p>\u5982\u4e0a\u56fe\uff0c\u6211\u4eec\u5728\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u91cc\u914d\u7f6e\u4e86\u56db\u4e2a\u73af\u5883\uff0c\u4e2d\u95f4\u662f\u901a\u8fc7\u201c\u2014\u201d\u5206\u5272\u6210\u56db\u4e2a\u6587\u6863\uff0c<strong>YAML \u6587\u4ef6\u53ef\u4ee5\u7531\u4e00\u6216\u591a\u4e2a\u6587\u6863\u7ec4\u6210\uff08\u4e5f\u5373\u76f8\u5bf9\u72ec\u7acb\u7684\u7ec4\u7ec7\u7ed3\u6784\u7ec4\u6210\uff09\uff0c\u6587\u6863\u95f4\u4f7f\u7528\u201c\u2014\u201d\uff08\u4e09\u4e2a\u6a2a\u7ebf\uff09\u5728\u6bcf\u6587\u6863\u5f00\u59cb\u4f5c\u4e3a\u5206\u9694\u7b26\u3002\u540c\u65f6\uff0c\u6587\u6863\u4e5f\u53ef\u4ee5\u4f7f\u7528\u201c\u2026\u201d\uff08\u4e09\u4e2a\u70b9\u53f7\uff09\u4f5c\u4e3a\u7ed3\u675f\u7b26(\u53ef\u9009)<\/strong><\/p>\n\n\n\n<p>\u8fd9\u56db\u79cd\u73af\u5883\u5c31\u662f\u9760spring.profiles\u914d\u7f6e\u7684\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u6ca1\u6709\u914d\u7f6e \u76f8\u5f53\u4e8e application.yaml  \u7b2c\u4e00\u5757 \nspring.profiles: dev \u76f8\u5f53\u4e8e application-dev.yaml  \u7b2c\u4e8c\u5757\nspring.profiles: test \u76f8\u5f53\u4e8e application-test.yaml  \u7b2c\u4e09\u5757 \nspring.profiles: prod \u76f8\u5f53\u4e8e application-prod.yaml  \u7b2c\u56db\u5757 <\/pre>\n\n\n\n<p>\u800c\u4e14 spring.profiles\u53ef\u4ee5\u8bbe\u5b9a\u591a\u4e2a\u540d\u79f0\uff0c\u4e2d\u95f4\u901a\u8fc7\u9017\u53f7\u5206\u5272,\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">spring.profiles: dev,dev1<\/pre>\n\n\n\n<p>\u90a3\u4e48\u5728\u4f7f\u7528\u65f6<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">spring.profiles.active: dev \n\u548c \nspring.profiles.active: dev1<\/pre>\n\n\n\n<p>\u90fd\u76f8\u5f53\u4e8e\u8fd9\u540c\u4e00\u4e2a\u914d\u7f6e\uff0cdev\u548cdev1\u53ea\u662f\u4e0d\u540c\u7684\u522b\u540d\u7f62\u4e86\u3002<\/p>\n\n\n\n<p><strong>spring.profiles.active<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u8fd9\u4e2a\u6ca1\u4ec0\u4e48\u597d\u8bb2\u7684\uff0c\u5927\u5bb6\u7ecf\u5e38\u7528\uff0c\u552f\u4e00\u8981\u8bb2\u7684\u662f\uff0c\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u4e5f\u662f\u901a\u8fc7\u9017\u53f7\u5206\u5272\uff0c\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">spring.profiles.active: dev,test<\/pre>\n\n\n\n<p>dev\u548ctest\u4e24\u4e2a\u914d\u7f6e\u91cc\u9762\uff0c\u76f8\u540c\u7684\u5c5e\u6027\u7684\uff0c\u8c01\u5199\u5728\u540e\u9762\u8c01\u4f18\u5148\u7ea7\u9ad8\u3002<br>\u6bd4\u5982\uff0cdev\u91cc\u9762name: zhangsan test\u91cc\u9762 name\uff1alisi\uff0c\u90a3\u4e48name:lisi \u751f\u6548\u3002<br>\u4e0d\u540c\u7684\u53d6\u5e76\u96c6\u3002<\/p>\n\n\n\n<p><strong>spring.profiles.include<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u9996\u5148 spring.profiles.include\u6709spring.profiles.active\u4e00\u6837\u7684\u4f5c\u7528\u3002\u53ef\u4ee5\u4f7f\u7528\u5bf9\u5e94\u7684\u914d\u7f6e\uff0c\u5176\u5b9espring.profiles.include\u7684\u5355\u7eaf\u4f5c\u7528\u5c31\u662f\u5c06\u591a\u4e2a\u914d\u7f6e\u6574\u5408\u8d77\u6765\uff0c<br>\u6bd4\u5982\u6211\u6709\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\u6bcf\u4e2a\u8d1f\u8d23\u4e00\u90e8\u5206\u914d\u7f6e\uff0c\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>application-prod_redis.yaml<\/li><li>application-prod_mq.yaml<\/li><li>application-prod_db.yaml<\/li><\/ul>\n\n\n\n<p>\u6211\u73b0\u5728\u53ea\u9700\u8981\u5728application-prod.yaml\u6587\u4ef6\u4e2d\u914d\u7f6e\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">spring.profiles.include: prod_redis,prod_mq,prod_db<\/pre>\n\n\n\n<p>\u8fd9\u6837\u53ea\u9700\u8981\u4f7f\u7528prod\u5c31\u540c\u65f6\u62e5\u6709\u4e86redis\u548cmq\uff0cdb\u7684\u914d\u7f6e\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>spring.profiles\u914d\u7f6e\u6587\u4ef6 \u8be6\u89e3 spring.profiles spring.profiles. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9242"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9242"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9242\/revisions"}],"predecessor-version":[{"id":9245,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9242\/revisions\/9245"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}