{"id":10006202,"date":"2022-08-15T10:43:38","date_gmt":"2022-08-15T02:43:38","guid":{"rendered":"https:\/\/ityet.com\/?p=10006202"},"modified":"2022-08-15T10:43:38","modified_gmt":"2022-08-15T02:43:38","slug":"%e9%9d%a2%e8%af%95%e7%aa%81%e5%87%bb74%ef%bc%9aproperties%e5%92%8cyml%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006202","title":{"rendered":"\u9762\u8bd5\u7a81\u51fb74\uff1aproperties\u548cyml\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p>properties \u548c yml \u90fd\u662f Spring Boot \u652f\u6301\u7684\u4e24\u79cd\u914d\u7f6e\u6587\u4ef6\uff0c\u5b83\u4eec\u53ef\u4ee5\u770b\u4f5c\u662f Spring Boot \u5728\u4e0d\u540c\u65f6\u671f\u7684\u4e24\u6b3e\u201c\u4ea7\u54c1\u201d\u3002\u5728 Spring Boot \u65f6\u4ee3\u5df2\u7ecf\u4e0d\u9700\u8981\u4f7f\u7528 XML \u6587\u4ef6\u683c\u5f0f\u6765\u914d\u7f6e\u9879\u76ee\u4e86\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u662f properties \u6216 yml \u6587\u4ef6\u3002<\/p>\n<p>properties \u914d\u7f6e\u6587\u4ef6\u5c5e\u4e8e\u65e9\u671f\uff0c\u4e5f\u662f\u76ee\u524d\u521b\u5efa Spring Boot\uff082.x\uff09\u9879\u76ee\u65f6\u9ed8\u8ba4\u7684\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f\uff0c\u800c yml \u53ef\u4ee5\u770b\u505a\u662f\u5bf9 properties \u914d\u7f6e\u6587\u4ef6\u7684\u5347\u7ea7\uff0c\u5c5e\u4e8e Spring Boot \u7684\u201c\u65b0\u7248\u201d\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>properties \u548c yml \u7684\u533a\u522b\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b 4 \u70b9\uff1a<\/p>\n<ol>\n<li>\u5b9a\u4e49\u548c\u5b9a\u4f4d\u4e0d\u540c\uff1b<\/li>\n<li>\u8bed\u6cd5\u4e0d\u540c\uff1b<\/li>\n<li>yml \u66f4\u597d\u7684\u914d\u7f6e\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff1b<\/li>\n<li>yml \u652f\u6301\u591a\u79cd\u8bed\u8a00\u3001\u901a\u7528\u6027\u66f4\u597d\u3002<\/li>\n<\/ol>\n<h2>\u533a\u522b1\uff1a\u5b9a\u4e49\u548c\u5b9a\u4f4d\u4e0d\u540c<\/h2>\n<p>properties \u7ffb\u8bd1\u6210\u4e2d\u6587\u662f\u201c\u5c5e\u6027\u201d\u7684\u610f\u601d\uff0c\u6240\u4ee5\u5b83\u5728\u521b\u5efa\u4e4b\u521d\uff0c\u5c31\u662f\u7528\u6765\u5728 Spring Boot \u4e2d\u8bbe\u7f6e\u5c5e\u6027\u7684\u3002<br \/>yml \u662f YAML \u662f\u7f29\u5199\uff0c\u5b83\u7684\u5168\u79f0 Yet Another Markup Language\uff0c\u7ffb\u8bd1\u6210\u4e2d\u6587\u662f\u201c\u53e6\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\u201d\u3002<\/p>\n<p>\u6240\u4ee5\u4ece\u4e8c\u8005\u7684\u5b9a\u4e49\u53ef\u4ee5\u770b\u51fa\uff1a\u5b83\u4eec\u7684\u5b9a\u4f4d\u548c\u5c42\u6b21\u662f\u5b8c\u5168\u4e0d\u540c\u7684\uff0cproperties \u53ea\u662f\u7528\u6765\u8bbe\u7f6e\u4e00\u4e9b\u5c5e\u6027\u914d\u7f6e\u7684\uff0c\u800c yml \u7684\u683c\u5c40\u548c\u613f\u666f\u66f4\u5927\uff0c\u5b83\u7684\u5b9a\u4f4d\u662f\u201c\u53e6\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\u201d\uff0c\u6240\u4ee5\u4ece\u683c\u5c40\u4e0a\u6765\u8bb2 yml \u5c31\u7529 properties \u597d\u51e0\u6761\u8857\u3002<\/p>\n<h2>\u533a\u522b2\uff1a\u8bed\u6cd5\u4e0d\u540c<\/h2>\n<p>properties \u548c yml \u8bed\u6cd5\u533a\u522b\u5f88\u5927\uff0cproperties \u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"properties\"># \u914d\u7f6e\u9879\u76ee\u542f\u52a8\u7aef\u53e3\u53f7\nserver.port=8088\n# \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\ndebug=true\n# \u914d\u7f6e\u6570\u636e\u8fde\u63a5\u4fe1\u606f\nspring.datasource.url=jdbc:mysql:\/\/127.0.0.0:3306\/dbname?characterEncoding=utf8\nspring.datasource.username=root\nspring.datasource.password=root\nspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver<\/code><\/pre>\n<p>\u4ece\u4e0a\u8ff0\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u770b\u51fa\uff1a<strong>properties \u7684\u57fa\u672c\u8bed\u6cd5\u683c\u5f0f\u662f\u201ckey=value\u201d\u7684\u5f62\u5f0f<\/strong>\uff0c\u800c yml \u7684\u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"yaml\"># \u914d\u7f6e\u9879\u76ee\u542f\u52a8\u7aef\u53e3\u53f7\nserver:\n  port: 9090\n# \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\ndebug: true\n# \u914d\u7f6e\u6570\u636e\u8fde\u63a5\u4fe1\u606f\nspring:\n  datasource:\n    url: jdbc:mysql:\/\/127.0.0.0:3306\/dbname?characterEncoding=utf8\n    username: root\n    password: root\n    driver-class-name: com.mysql.cj.jdbc.Driver<\/code><\/pre>\n<p>\u4ece\u4e0a\u8ff0\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u770b\u51fa\uff1a<strong>yml \u7684\u57fa\u672c\u8bed\u6cd5\u683c\u5f0f\u662f\u201ckey: value\u201d\u7684\u5f62\u5f0f<\/strong>\uff0c\u4e14\u5192\u53f7\u540e\u9762\u7684\u7a7a\u683c\u662f\u4e0d\u80fd\u88ab\u7701\u7565\u7684\uff0c\u5426\u5219\u9879\u76ee\u542f\u52a8\u4f1a\u62a5\u9519\uff1a<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042318655\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><br \/>\u4ece\u4e0a\u8ff0 properties \u548c yml \u914d\u7f6e\u6570\u636e\u5e93\u7684\u8fde\u63a5\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c<strong>\u76f8\u6bd4\u4e8e properties \u6765\u8bf4\uff0cyml \u7684\u8bed\u6cd5\u66f4\u7b80\u6d01\uff0c\u5e76\u4e14\u53ef\u8bfb\u6027\u66f4\u9ad8<\/strong>\uff0c\u5b83\u4eec\u7684\u533a\u522b\u5982\u4e0b\uff1a<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042318656\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h2>\u533a\u522b3\uff1ayml \u66f4\u597d\u7684\u914d\u7f6e\u591a\u79cd\u6570\u636e\u7c7b\u578b<\/h2>\n<p>yml \u9664\u4e86\u53ef\u4ee5\u5f88\u597d\u7684\u914d\u7f6e\u57fa\u7840\u6570\u636e\u7c7b\u578b\u4e4b\u5916\uff0c\u5b83\u8fd8\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u914d\u7f6e\u5bf9\u8c61\u3001\u96c6\u5408\u7b49\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u5728 yml \u4e2d\u914d\u7f6e\u5bf9\u8c61\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"yaml\">student:\n  id: 1\n  name: Java\n  age: 18<\/code><\/pre>\n<p>\u6216\u8005\u662f\u4f7f\u7528\u884c\u5185\u5199\u6cd5\u914d\u7f6e\u5bf9\u8c61\u7c7b\u578b\uff08\u4e0e\u4e0a\u9762\u7684\u5199\u6cd5\u7684\u6548\u679c\u4e00\u81f4\uff09\uff1a<\/p>\n<pre><code class=\"yaml\">student: {id: 1,name: Java,age: 18}<\/code><\/pre>\n<p>\u5728 yml \u4e2d\u914d\u7f6e\u6570\u7ec4\u4e5f\u6709\u4e24\u79cd\u5199\u6cd5\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<pre><code class=\"yaml\">animal:\n  - Dog\n  - Cat<\/code><\/pre>\n<p>\u6216\u8005\u4f7f\u7528\u884c\u5185\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"yaml\">animal: [Dog, Cat]<\/code><\/pre>\n<h2>\u533a\u522b4\uff1ayml \u53ef\u4ee5\u8de8\u8bed\u8a00<\/h2>\n<p>properties \u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u53ea\u9002\u7528\u4e8e Spring Boot \u9879\u76ee\uff0c\u4e5f\u5c31\u662f\u53ea\u9002\u7528\u4e8e Java \u8bed\u8a00\uff0c\u800c yml \u652f\u6301\u66f4\u591a\u7684\u5f00\u53d1\u8bed\u8a00\uff0c\u5b83\u53ef\u4ee5\u7528\u5728 Java\u3001PHP\u3001Python\u3001Ruby\u3001JavaScript\u3001Perl\u3001Golang \u7b49\u8bed\u8a00\u4e2d\u3002<\/p>\n<p>\u81f3\u4e8e\u4f5c\u7528\u561b\uff1f\u5982\u679c\u4e00\u4e2a\u516c\u53f8\u6709\u591a\u4e2a\u4e0d\u540c\u8bed\u8a00\u7684\u5f00\u53d1\u56e2\u961f\uff0c\u5e76\u4e14\u4f7f\u7528\u4e86\u914d\u7f6e\u4e2d\u5fc3\uff08\u5728\u7ebf\u914d\u7f6e\u6587\u4ef6\uff09\u7684\u524d\u63d0\u4e0b\uff0c\u90a3\u4e48\u8fd9\u4e9b\u4e0d\u540c\u8bed\u8a00\u7684\u5f00\u53d1\u56e2\u961f\u5c31\u53ef\u4ee5\u4f7f\u7528\u540c\u4e00\u4efd\u914d\u7f6e\u6587\u4ef6\u4e86\uff0c\u4e5f\u65b9\u4fbf\u540e\u671f\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>properties \u548c yml \u90fd\u662f Spring Boot \u652f\u6301\u7684\u4e24\u79cd\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2d yml \u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u770b\u4f5c\u662f\u5bf9 properties  \u914d\u7f6e\u6587\u4ef6\u7684\u5347\u7ea7\u3002\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\u6709 4 \u70b9\uff1a\u5b9a\u4e49\u548c\u5b9a\u4f4d\u4e0d\u540c\u3001\u8bed\u6cd5\u4e0d\u540c\uff1ayml \u7684\u8bed\u6cd5\u66f4\u7b80\u5355\uff0c\u4e14\u53ef\u8bfb\u6027\u66f4\u9ad8\u3001yml \u53ef\u4ee5\u66f4\u597d\u7684\u914d\u7f6e\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u5bf9\u8c61\u548c\u96c6\u5408\u3001yml \u53ef\u4ee5\u8de8\u8bed\u8a00\u4f7f\u7528\uff0c\u901a\u7528\u6027\u66f4\u597d\u3002<\/p>\n<blockquote>\n<p>\u662f\u975e\u5ba1\u4e4b\u4e8e\u5df1\uff0c\u6bc1\u8a89\u542c\u4e4b\u4e8e\u4eba\uff0c\u5f97\u5931\u5b89\u4e4b\u4e8e\u6570\u3002<\/p>\n<p>\u516c\u4f17\u53f7\uff1aJava\u9762\u8bd5\u771f\u9898\u89e3\u6790<\/p>\n<p>\u9762\u8bd5\u5408\u96c6\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ojHaH3C9%2BxyKT%2B1txWAfsw%3D%3D.ilHWaCyCYdJBpUm3W5kykIfpy74X43P2JWQFyhBVpJtnqHt0rPLNIhZFgPZzumuv\" rel=\"nofollow\">https:\/\/gitee.com\/mydb\/interview<\/a><\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042318653\">https:\/\/segmentfault.com\/a\/1190000042318653<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>properties \u548c yml \u90fd\u662f Spring Boot \u652f\u6301\u7684\u4e24\u79cd\u914d\u7f6e\u6587\u4ef6\uff0c\u5b83\u4eec\u53ef\u4ee5\u770b\u4f5c\u662f Sprin [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006202","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006202"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006202\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}