{"id":4329,"date":"2021-12-03T14:03:56","date_gmt":"2021-12-03T06:03:56","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4329"},"modified":"2021-12-03T14:03:56","modified_gmt":"2021-12-03T06:03:56","slug":"spring-boot%e9%bb%98%e8%ae%a4%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4329","title":{"rendered":"Spring Boot\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0cSpring Boot \u5728\u542f\u52a8\u65f6\u4f1a\u5c06 resources \u76ee\u5f55\u4e0b\u7684 application.properties \u6216 apllication.yml \u4f5c\u4e3a\u5176\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8be5\u914d\u7f6e\u6587\u4ef6\u4e2d\u5bf9\u9879\u76ee\u8fdb\u884c\u914d\u7f6e\uff0c\u4f46\u8fd9\u5e76\u4e0d\u610f\u5473\u7740 Spring Boot \u9879\u76ee\u4e2d\u53ea\u80fd\u5b58\u5728\u4e00\u4e2a application.properties \u6216 application.yml\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6<\/h5>\n\n\n\n<p>Spring Boot \u9879\u76ee\u4e2d\u53ef\u4ee5\u5b58\u5728\u591a\u4e2a application.properties \u6216 apllication.yml\u3002<br><br>Spring Boot \u542f\u52a8\u65f6\u4f1a\u626b\u63cf\u4ee5\u4e0b 5 \u4e2a\u4f4d\u7f6e\u7684&nbsp; application.properties \u6216 apllication.yml \u6587\u4ef6\uff0c\u5e76\u5c06\u5b83\u4eec\u4f5c\u4e3a Spring boot \u7684\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<ol><li>file:.\/config\/<\/li><li>file:.\/config\/*\/<\/li><li>file:.\/<\/li><li>classpath:\/config\/<\/li><li>classpath:\/<\/li><\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6ce8\uff1afile: \u6307\u5f53\u524d\u9879\u76ee\u6839\u76ee\u5f55\uff1bclasspath: \u6307\u5f53\u524d\u9879\u76ee\u7684\u7c7b\u8def\u5f84\uff0c\u5373 resources \u76ee\u5f55\u3002<\/p><\/blockquote>\n\n\n\n<p>\u4ee5\u4e0a\u6240\u6709\u4f4d\u7f6e\u7684\u914d\u7f6e\u6587\u4ef6\u90fd\u4f1a\u88ab\u52a0\u8f7d\uff0c\u4e14\u5b83\u4eec\u4f18\u5148\u7ea7\u4f9d\u6b21\u964d\u4f4e\uff0c\u5e8f\u53f7\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8\u3002\u5176\u6b21\uff0c\u4f4d\u4e8e\u76f8\u540c\u4f4d\u7f6e\u7684 application.properties \u7684\u4f18\u5148\u7ea7\u9ad8\u4e8e application.yml\u3002<br><br>\u6240\u6709\u4f4d\u7f6e\u7684\u6587\u4ef6\u90fd\u4f1a\u88ab\u52a0\u8f7d\uff0c\u9ad8\u4f18\u5148\u7ea7\u914d\u7f6e\u4f1a\u8986\u76d6\u4f4e\u4f18\u5148\u7ea7\u914d\u7f6e\uff0c\u5f62\u6210\u4e92\u8865\u914d\u7f6e\uff0c\u5373\uff1a<\/p>\n\n\n\n<ul><li>\u5b58\u5728\u76f8\u540c\u7684\u914d\u7f6e\u5185\u5bb9\u65f6\uff0c\u9ad8\u4f18\u5148\u7ea7\u7684\u5185\u5bb9\u4f1a\u8986\u76d6\u4f4e\u4f18\u5148\u7ea7\u7684\u5185\u5bb9\uff1b<\/li><li>\u5b58\u5728\u4e0d\u540c\u7684\u914d\u7f6e\u5185\u5bb9\u65f6\uff0c\u9ad8\u4f18\u5148\u7ea7\u548c\u4f4e\u4f18\u5148\u7ea7\u7684\u914d\u7f6e\u5185\u5bb9\u53d6\u5e76\u96c6\u3002<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\u793a\u4f8b<\/h5>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a springbootdemo \u7684 Spring Boot \u9879\u76ee\uff0c\u5e76\u5728\u5f53\u524d\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u3001\u7c7b\u8def\u5f84\u4e0b\u7684 config \u76ee\u5f55\u4e0b\u3001\u4ee5\u53ca\u7c7b\u8def\u5f84\u4e0b\u5206\u522b\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6 application.yml\uff0c\u8be5\u9879\u76ee\u7ed3\u6784\u5982\u4e0b\u56fe\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\/2021\/12\/image-78-1024x951.png\" alt=\"\" class=\"wp-image-4330\" width=\"597\" height=\"554\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-1024x951.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-300x279.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-768x713.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-830x771.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-230x214.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-350x325.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78-480x446.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-78.png 1062w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/figure><\/div>\n\n\n\n<p>\u9879\u76ee\u6839\u8def\u5f84\u4e0b\u914d\u7f6e\u6587\u4ef6 application.yml \u914d\u7f6e\u5982\u4e0b\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=\"\">    #\u9879\u76ee\u66f4\u76ee\u5f55\u4e0b\n    #\u4e0a\u4e0b\u6587\u8def\u5f84\u4e3a \/abc\n    server:\n      servlet:\n        context-path: \/abc<\/pre>\n\n\n\n<p>\u9879\u76ee\u7c7b\u8def\u5f84\u4e0b config \u76ee\u5f55\u4e0b\u914d\u7f6e\u6587\u4ef6 application.yml \u914d\u7f6e\u5982\u4e0b\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=\"\">    #\u7c7b\u8def\u5f84\u4e0b\u7684 config \u76ee\u5f55\u4e0b\n    #\u7aef\u53e3\u53f7\u4e3a8084\n    #\u4e0a\u4e0b\u6587\u8def\u5f84\u4e3a \/helloWorld\n    server:\n      port: 8084\n      servlet:\n        context-path: \/helloworld<\/pre>\n\n\n\n<p>\u9879\u76ee\u7c7b\u8def\u5f84\u4e0b\u7684 application.yml \u914d\u7f6e\u5982\u4e0b\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=\"\">    #\u9ed8\u8ba4\u914d\u7f6e\n    server:\n      port: 8080<\/pre>\n\n\n\n<p>\u5728 net.biancheng.www.controller \u5305\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a MyController \u7684\u7c7b\uff0c\u4ee3\u7801\u5982\u4e0b\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=\"\">    package net.biancheng.www.controller;\n    import org.springframework.web.bind.annotation.RequestMapping;\n    import org.springframework.web.bind.annotation.ResponseBody;\n    import org.springframework.web.bind.annotation.RestController;\n    @RestController\n    public class MyController {\n        @ResponseBody\n        @RequestMapping(\"\/test\")\n        public String hello() {\n            return \"hello Spring Boot!\";\n        }\n    }<\/pre>\n\n\n\n<p>\u542f\u52a8 Spring Boot\uff0c\u67e5\u770b\u63a7\u5236\u53f0\u8f93\u51fa\uff0c\u5982\u4e0b\u56fe\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\/2021\/12\/image-79-1024x301.png\" alt=\"\" class=\"wp-image-4331\" width=\"602\" height=\"176\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-1024x301.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-300x88.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-768x226.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-1536x451.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-830x244.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-230x68.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-350x103.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79-480x141.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-79.png 1770w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure><\/div>\n\n\n\n<p>\u6839\u636e Spring Boot \u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u4f18\u5148\u7ea7\u8fdb\u884c\u5206\u6790\uff1a<\/p>\n\n\n\n<ul><li>\u8be5\u9879\u76ee\u4e2d\u5b58\u5728\u591a\u4e2a\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2d\u6839\u76ee\u5f55\u4e0b&nbsp;\/config \u76ee\u5f55\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\u4f18\u5148\u7ea7\u6700\u9ad8\uff0c\u56e0\u6b64\u9879\u76ee\u7684\u4e0a\u4e0b\u6587\u8def\u5f84\u4e3a \u201c\/abc\u201d\uff1b<\/li><li>\u7c7b\u8def\u5f84\uff08classpath\uff09\u4e0b config \u76ee\u5f55\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\u4f18\u5148\u7ea7\u9ad8\u4e8e\u7c7b\u8def\u5f84\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u56e0\u6b64\u8be5\u9879\u76ee\u7684\u7aef\u53e3\u53f7\u4e3a \u201c8084\u201d\uff1b<\/li><li>\u4ee5\u4e0a\u6240\u6709\u914d\u7f6e\u9879\u5f62\u6210\u4e92\u8865\uff0c\u6240\u4ee5\u8bbf\u95ee\u8def\u5f84\u4e3a\u201chttp:\/\/localhost:8084\/abc\u201d\u3002<\/li><\/ul>\n\n\n\n<p>\u6839\u636e\u670d\u52a1\u5668\u7aef\u53e3\u548c\u4e0a\u4e0b\u6587\u8def\u5f84\uff0c\u4f7f\u7528\u6d4f\u89c8\u5668\u8bbf\u95ee\u00a0http:\/\/localhost:8084\/abc\/test\uff0c\u7ed3\u679c\u5982\u4e0b\u56fe\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\/2021\/12\/image-80-1024x304.png\" alt=\"\" class=\"wp-image-4332\" width=\"612\" height=\"181\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-1024x304.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-300x89.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-768x228.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-830x246.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-230x68.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-350x104.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80-480x142.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-80.png 1274w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0cSpring Boot \u5728\u542f\u52a8\u65f6\u4f1a\u5c06 resources \u76ee\u5f55\u4e0b\u7684 application.pro [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4329"}],"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=4329"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4329\/revisions"}],"predecessor-version":[{"id":4333,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4329\/revisions\/4333"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}