{"id":8316,"date":"2023-11-28T20:24:39","date_gmt":"2023-11-28T12:24:39","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8316"},"modified":"2023-12-06T10:17:44","modified_gmt":"2023-12-06T02:17:44","slug":"springboot-he-xin-pei-zhi-wen-jian-shi-shen-me-boo-2","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/springboot-he-xin-pei-zhi-wen-jian-shi-shen-me-boo-2\/","title":{"rendered":"SpringBoot \u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u662f\u4ec0\u4e48\uff1f bootstrap.properties \u548c application.properties \u6709\u4f55\u533a\u522b ?"},"content":{"rendered":"<p>\u5728Spring Boot\u4e2d\uff0c\u6838\u5fc3\u7684\u914d\u7f6e\u6587\u4ef6\u6709\u4e24\u4e2a\uff0c\u5206\u522b\u662f <code>application.properties<\/code> \u548c <code>application.yml<\/code>\u3002\u8fd9\u4e24\u4e2a\u6587\u4ef6\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u5404\u79cd\u5c5e\u6027\uff0c\u5305\u62ec\u6570\u636e\u5e93\u8fde\u63a5\u3001\u670d\u52a1\u5668\u7aef\u53e3\u3001\u65e5\u5fd7\u914d\u7f6e\u7b49\u3002<\/p>\n<ol>\n<li>\n<strong><code>application.properties<\/code>\uff1a<\/strong><\/p>\n<ul>\n<li><code>application.properties<\/code> \u662f\u57fa\u4e8e\u5c5e\u6027\u952e\u503c\u5bf9\uff08key=value\uff09\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f7f\u7528\u7b80\u5355\u7684\u6587\u672c\u683c\u5f0f\u3002<\/li>\n<li>\u901a\u5e38\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u5c5e\u6027\uff0c\u5982\u6570\u636e\u5e93\u8fde\u63a5\u3001\u7aef\u53e3\u53f7\u3001\u65e5\u5fd7\u7ea7\u522b\u7b49\u3002<\/li>\n<li>\u793a\u4f8b\uff1a\n<pre><code class=\"language-properties\"># \u6570\u636e\u5e93\u914d\u7f6e\nspring.datasource.url=jdbc:mysql:\/\/localhost:3306\/mydatabase\nspring.datasource.username=user\nspring.datasource.password=pass\n\n# \u670d\u52a1\u5668\u7aef\u53e3\nserver.port=8080\n\n# \u65e5\u5fd7\u7ea7\u522b\nlogging.level.root=info\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong><code>application.yml<\/code>\uff1a<\/strong><\/p>\n<ul>\n<li><code>application.yml<\/code> \u662f\u57fa\u4e8e YAML\uff08YAML Ain&#8217;t Markup Language\uff09\u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f7f\u7528\u4e86\u66f4\u52a0\u4eba\u7c7b\u53ef\u8bfb\u7684\u7f29\u8fdb\u683c\u5f0f\u3002<\/li>\n<li>\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8868\u793a\u590d\u6742\u7684\u914d\u7f6e\u7ed3\u6784\uff0c\u5982\u591a\u7ea7\u5c5e\u6027\u3001\u5217\u8868\u7b49\u3002<\/li>\n<li>\u793a\u4f8b\uff1a\n<pre><code class=\"language-yaml\"># \u6570\u636e\u5e93\u914d\u7f6e\nspring:\n  datasource:\n    url: jdbc:mysql:\/\/localhost:3306\/mydatabase\n    username: user\n    password: pass\n\n# \u670d\u52a1\u5668\u7aef\u53e3\nserver:\n  port: 8080\n\n# \u65e5\u5fd7\u7ea7\u522b\nlogging:\n  level:\n    root: info\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u5173\u4e8e <code>bootstrap.properties<\/code>\uff0c\u5b83\u662f\u4e00\u4e2a\u53ef\u9009\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8e\u5728Spring Boot\u542f\u52a8\u8fc7\u7a0b\u4e2d\u52a0\u8f7d\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u4e4b\u524d\u914d\u7f6e\u4e00\u4e9b\u5c5e\u6027\u3002\u901a\u5e38\uff0c\u5b83\u7528\u4e8e\u914d\u7f6e\u4e00\u4e9b\u4e0e\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u52a0\u8f7d\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u4f8b\u5982\u914d\u7f6e\u4e2d\u5fc3\u7684\u5730\u5740\u7b49\u3002<\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c<code>application.properties<\/code> \u548c <code>application.yml<\/code> \u662f\u4e3b\u8981\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8e\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u5404\u79cd\u5c5e\u6027\u3002\u5b83\u4eec\u7684\u533a\u522b\u5728\u4e8e\u6587\u4ef6\u683c\u5f0f\u548c\u4e66\u5199\u98ce\u683c\u3002\u800c <code>bootstrap.properties<\/code> \u5219\u7528\u4e8e\u5728Spring Boot\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u8fdb\u884c\u4e00\u4e9b\u7279\u6b8a\u7684\u914d\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Spring Boot\u4e2d\uff0c\u6838\u5fc3\u7684\u914d\u7f6e\u6587\u4ef6\u6709\u4e24\u4e2a\uff0c\u5206\u522b\u662f application.properties \u548c a [&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-8316","post","type-post","status-publish","format-standard","hentry","category-springboot"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8316","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=8316"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8316\/revisions"}],"predecessor-version":[{"id":16596,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8316\/revisions\/16596"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8316"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}