{"id":8577,"date":"2023-11-28T20:31:43","date_gmt":"2023-11-28T12:31:43","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8577"},"modified":"2023-12-06T10:46:32","modified_gmt":"2023-12-06T02:46:32","slug":"springboot-zhong-bootstrapyml-he-applicationyml-yo","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/springboot-zhong-bootstrapyml-he-applicationyml-yo\/","title":{"rendered":"SpringBoot \u4e2d bootstrap.yml \u548c application.yml \u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p>\u5728 Spring Boot \u4e2d\uff0c<code>bootstrap.yml<\/code> \u548c <code>application.yml<\/code> \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5b83\u4eec\u6709\u4e0d\u540c\u7684\u52a0\u8f7d\u65f6\u673a\u548c\u4f5c\u7528\u3002\u4ee5\u4e0b\u662f\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\uff1a<\/p>\n<ol>\n<li>\n<strong>\u52a0\u8f7d\u65f6\u673a\uff1a<\/strong><\/p>\n<ul>\n<li><code>bootstrap.yml<\/code> \u662f\u5728 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u9636\u6bb5\u7684\u6700\u65e9\u65f6\u673a\u52a0\u8f7d\u7684\uff0c\u7528\u4e8e\u914d\u7f6e\u4e00\u4e9b\u5f15\u5bfc\u9636\u6bb5\u9700\u8981\u7684\u5c5e\u6027\u3002\u901a\u5e38\uff0c\u5b83\u7528\u4e8e\u914d\u7f6e\u4e0e\u914d\u7f6e\u4e2d\u5fc3\uff08\u5982 Spring Cloud Config\uff09\u76f8\u5173\u7684\u5c5e\u6027\u3002<\/li>\n<li><code>application.yml<\/code> \u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u4e0a\u4e0b\u6587\u51c6\u5907\u597d\u4e4b\u540e\u52a0\u8f7d\u7684\uff0c\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u822c\u5c5e\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u4f5c\u7528\u8303\u56f4\uff1a<\/strong><\/p>\n<ul>\n<li><code>bootstrap.yml<\/code> \u4e3b\u8981\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e9b\u57fa\u7840\u8bbe\u65bd\uff0c\u5982\u914d\u7f6e\u4e2d\u5fc3\u7684\u914d\u7f6e\u3001\u52a0\u5bc6\u5bc6\u94a5\u7b49\u3002\u5b83\u7684\u5c5e\u6027\u53ef\u4ee5\u5728\u6574\u4e2a Spring \u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002<\/li>\n<li><code>application.yml<\/code> \u4e3b\u8981\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u529f\u80fd\uff0c\u5305\u62ec\u6570\u636e\u5e93\u8fde\u63a5\u3001\u670d\u52a1\u7aef\u53e3\u3001\u4e1a\u52a1\u76f8\u5173\u914d\u7f6e\u7b49\u3002\u5b83\u7684\u5c5e\u6027\u4e5f\u53ef\u4ee5\u5728\u6574\u4e2a Spring \u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u8986\u76d6\u5173\u7cfb\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u5b58\u5728\u76f8\u540c\u7684\u5c5e\u6027\u952e\uff0c<code>bootstrap.yml<\/code> \u4e2d\u7684\u5c5e\u6027\u4f1a\u8986\u76d6 <code>application.yml<\/code> \u4e2d\u7684\u5c5e\u6027\u3002\u8fd9\u662f\u56e0\u4e3a <code>bootstrap.yml<\/code> \u5728\u52a0\u8f7d\u65f6\u673a\u4e0a\u66f4\u65e9\uff0c\u6240\u4ee5\u5177\u6709\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u4f7f\u7528\u573a\u666f\uff1a<\/strong><\/p>\n<ul>\n<li><code>bootstrap.yml<\/code> \u9002\u7528\u4e8e\u4e00\u4e9b\u6bd4\u8f83\u654f\u611f\u6216\u57fa\u7840\u7684\u914d\u7f6e\uff0c\u4f8b\u5982\u914d\u7f6e\u4e2d\u5fc3\u7684\u5730\u5740\u3001\u52a0\u5bc6\u76f8\u5173\u7684\u914d\u7f6e\u7b49\u3002<\/li>\n<li><code>application.yml<\/code> \u9002\u7528\u4e8e\u4e00\u822c\u7684\u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\uff0c\u5305\u62ec\u6570\u636e\u5e93\u3001\u7f13\u5b58\u3001\u4e1a\u52a1\u903b\u8f91\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-yaml\"># bootstrap.yml\n\nspring:\n  cloud:\n    config:\n      uri: http:\/\/config-server:8888\n      name: myapplication\n<\/code><\/pre>\n<pre><code class=\"language-yaml\"># application.yml\n\nserver:\n  port: 8080\n\nspring:\n  datasource:\n    url: jdbc:mysql:\/\/localhost:3306\/mydatabase\n    username: root\n    password: secret\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<code>bootstrap.yml<\/code> \u4e2d\u914d\u7f6e\u4e86\u914d\u7f6e\u4e2d\u5fc3\u7684\u5730\u5740\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0c\u800c <code>application.yml<\/code> \u4e2d\u914d\u7f6e\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u7aef\u53e3\u4ee5\u53ca\u6570\u636e\u5e93\u8fde\u63a5\u7b49\u4e00\u822c\u914d\u7f6e\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u5408\u7406\u4f7f\u7528\u8fd9\u4e24\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u4f7f\u5f97\u914d\u7f6e\u66f4\u6709\u5c42\u6b21\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Spring Boot \u4e2d\uff0cbootstrap.yml \u548c application.yml \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u914d [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"class_list":["post-8577","post","type-post","status-publish","format-standard","hentry","category-springboot"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8577"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8577\/revisions"}],"predecessor-version":[{"id":16634,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8577\/revisions\/16634"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8577"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}