{"id":14593,"date":"2024-04-16T19:20:45","date_gmt":"2024-04-16T11:20:45","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=14593"},"modified":"2024-05-10T10:05:56","modified_gmt":"2024-05-10T02:05:56","slug":"%e5%85%a5%e5%9d%91-spring-boot%ef%bc%88%e7%bc%96%e8%be%91%e4%b8%ad%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=14593","title":{"rendered":"Spring Boot \u5b66\u4e60\u8bb0\u5f55"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#1_%E5%89%8D%E8%A8%80\" >1 \u524d\u8a00<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#2_%E7%8E%AF%E5%A2%83\" >2 \u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#3_%E8%BE%85%E5%8A%A9\" >3 \u8f85\u52a9<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#31_%E9%A1%B9%E7%9B%AE%E5%88%9B%E5%BB%BA%E5%99%A8\" >3.1 \u9879\u76ee\u521b\u5efa\u5668<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#311_%E5%AE%98%E6%96%B9%E7%BD%91%E7%AB%99\" >3.1.1 \u5b98\u65b9\u7f51\u7ad9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#312_VScode\" >3.1.2 VScode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#313_IDEA\" >3.1.3 IDEA<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#32_%E6%96%87%E6%A1%A3\" >3.2 \u6587\u6863<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#4_%E2%80%9CHello_world%E2%80%9D_%E4%BD%93%E9%AA%8C\" >4 \u201cHello world\u201d \u4f53\u9a8c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#5_%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\" >5 \u914d\u7f6e\u6587\u4ef6<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#51_%E5%85%AC%E5%85%B1%E5%BA%94%E7%94%A8%E5%B1%9E%E6%80%A7\" >5.1 \u516c\u5171\u5e94\u7528\u5c5e\u6027<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#52_%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\" >5.2 \u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#521_%E9%80%90%E4%B8%AA%E8%AF%BB%E5%8F%96\" >5.2.1 \u9010\u4e2a\u8bfb\u53d6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#522_%E6%8C%89%E9%9C%80%E8%8E%B7%E5%8F%96\" >5.2.2 \u6309\u9700\u83b7\u53d6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#523_%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96\" >5.2.3 \u53cd\u5e8f\u5217\u5316<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#53_%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%88%86%E7%B1%BB\" >5.3 \u914d\u7f6e\u6587\u4ef6\u5206\u7c7b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#531_%E5%A4%9A%E6%96%87%E4%BB%B6\" >5.3.1 \u591a\u6587\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#532_%E5%8D%95%E6%96%87%E4%BB%B6%E5%88%86%E6%AE%B5\" >5.3.2 \u5355\u6587\u4ef6\u5206\u6bb5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#533_%E8%BF%90%E8%A1%8C%E6%97%B6%E6%8C%87%E5%AE%9A%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\" >5.3.3 \u8fd0\u884c\u65f6\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/blog.iyatt.com\/?p=14593\/#54_%E5%A4%96%E9%83%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\" >5.4 \u5916\u90e8\u914d\u7f6e\u6587\u4ef6<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1_%E5%89%8D%E8%A8%80\"><\/span>1 \u524d\u8a00<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u53bb\u5e74\u63a5\u8fc7\u4e00\u4e2a Java \u7684\u5355\u5b50\uff0c\u73b0\u5b66\u4e86 Java\uff08<a href=\"https:\/\/blog.iyatt.com\/?p=11305\">https:\/\/blog.iyatt.com\/?p=11305<\/a> \uff09\uff0c\u5728\u4e4b\u540e\u90fd\u6ca1\u78b0\u8fc7 Java \u4e86\u3002<br \/>\n\u524d\u6bb5\u65f6\u95f4\u53c8\u9047\u5230\u4e00\u4e2a Spring Boot \u7684\u9879\u76ee\uff0c\u56e0\u4e3a\u65f6\u95f4\u6bd4\u8f83\u7d27\u53ea\u6709\u4e09\u56db\u5929\u5c31\u8981\u89c1\u521d\u7248\uff0c\u6211\u4e5f\u4e0d\u80fd\u73b0\u5b66\u6765\u505a\u5c31\u63a8\u6389\u4e86\u3002<br \/>\n\u73b0\u5728\u62bd\u7a7a\u5b66\u4e00\u4e0b\uff0c\u505a\u4e2a\u8bb0\u5f55\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"2_%E7%8E%AF%E5%A2%83\"><\/span>2 \u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Java 21.0.2<\/li>\n<li>Maven 3.9.6<\/li>\n<li>Spring Boot 3.2.4<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"3_%E8%BE%85%E5%8A%A9\"><\/span>3 \u8f85\u52a9<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"31_%E9%A1%B9%E7%9B%AE%E5%88%9B%E5%BB%BA%E5%99%A8\"><\/span>3.1 \u9879\u76ee\u521b\u5efa\u5668<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"311_%E5%AE%98%E6%96%B9%E7%BD%91%E7%AB%99\"><\/span>3.1.1 \u5b98\u65b9\u7f51\u7ad9<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Spring Boot \u9879\u76ee\u521b\u5efa\u5668\uff1a<a href=\"https:\/\/start.spring.io\/\">https:\/\/start.spring.io\/<\/a><br \/>\n\u8fd9\u4e2a\u662f\u5b98\u65b9\u63d0\u4f9b\u7684\uff0c\u800c\u4e14\u662f\u5f00\u6e90\u7684\uff0c\u81ea\u5df1\u4e5f\u53ef\u4ee5\u90e8\u7f72\u8fd9\u4e2a\u7f51\u9875<br \/>\n\u5de6\u4fa7\u914d\u7f6e\u57fa\u672c\u4fe1\u606f\uff0c\u53f3\u4fa7\u6dfb\u52a0\u5176\u5b83\u4f9d\u8d56<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713265740190.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1511px; --smush-placeholder-aspect-ratio: 1511\/780;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"312_VScode\"><\/span>3.1.2 VScode<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5982\u679c\u50cf\u6211\u4e00\u6837\u662f\u4f7f\u7528 VScode \u5f00\u53d1\uff0c\u53ef\u4ee5\u5b89\u88c5\u4e00\u4e2a\u63d2\u4ef6\uff0c\u5b9e\u73b0\u9879\u76ee\u521b\u5efa\uff08\u611f\u89c9\u5e94\u8be5\u4e5f\u662f\u57fa\u4e8e\u4e0a\u9762\u7684\u5b98\u65b9\u9879\u76ee\uff09\uff0c\u53ef\u4ee5\u4e0d\u9700\u8981\u624b\u52a8\u89e3\u5305\u6253\u5f00\u9879\u76ee\uff0c\u8fd9\u4e2a\u76f4\u63a5\u8df3\u8f6c\u5230\u521b\u5efa\u597d\u7684\u9879\u76ee<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713268628414.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 820px; --smush-placeholder-aspect-ratio: 820\/168;\" \/><\/p>\n<p>\u6309<code class=\"kb-btn\">F1<\/code>\u6216\u8005<code class=\"kb-btn\">Ctrl<\/code>+<code class=\"kb-btn\">Shift<\/code>+<code class=\"kb-btn\">P<\/code>\u6253\u5f00 VScode \u7684\u547d\u4ee4\u9762\u677f\uff0c\u641c\u7d22 Spring\uff0c\u5f00\u59cb\u521b\u5efa\u4e00\u4e2a Maven \u6216 Gradle \u9879\u76ee\uff0c\u540e\u7eed\u586b\u7684\u53c2\u6570\u548c\u7f51\u9875\u4e00\u6837<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713269009597.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 626px; --smush-placeholder-aspect-ratio: 626\/130;\" \/><\/p>\n<hr \/>\n<p>\u9664\u4e86\u4e0a\u9762\u7684\u9879\u76ee\u521b\u5efa\u63d2\u4ef6\uff0cVScode \u4e2d\u8fdb\u884c Spring Boot \u5f00\u53d1\u53ef\u80fd\u7528\u5230\u7684\u5176\u5b83\u63d2\u4ef6\uff1a<\/p>\n<ul>\n<li>\n<p>Java \u63d2\u4ef6\u96c6\u5408\uff1aExtension Pack for Java<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713271734563.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 744px; --smush-placeholder-aspect-ratio: 744\/437;\" \/><\/p>\n<\/li>\n<li>\n<p>Spring Boot \u4eea\u8868\u76d8\uff1aSpring Boot Dashboard<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713271797012.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 586px; --smush-placeholder-aspect-ratio: 586\/169;\" \/><br \/>\n\u5728\u4fa7\u8fb9\u680f\u4f1a\u663e\u793a\u6240\u6709\u7684 Spring Boot \u9879\u76ee\uff0c\u53ef\u4ee5\u96c6\u4e2d\u8c03\u8bd5\u548c\u8fd0\u884c\u7ba1\u7406<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713271842639.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 551px; --smush-placeholder-aspect-ratio: 551\/821;\" \/><\/p>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"313_IDEA\"><\/span>3.1.3 IDEA<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5982\u679c\u7528 IDEA\uff082023.1\uff09\uff0c\u4e5f\u53ef\u4ee5\u7528\u540c\u6837\u7684\u65b9\u6cd5\u521b\u5efa\uff0c\u8fd9\u4e2a\u9ed8\u8ba4\u5c31\u662f\u8c03\u7528\u5b98\u65b9\u7684\u521b\u5efa\u5668\u7f51\u7ad9<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713269375075.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 790px; --smush-placeholder-aspect-ratio: 790\/717;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"32_%E6%96%87%E6%A1%A3\"><\/span>3.2 \u6587\u6863<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/spring.io\/projects\/spring-boot#learn\">https:\/\/spring.io\/projects\/spring-boot#learn<\/a><br \/>\n\u4e2d\u6587\u6587\u6863\uff1a<a href=\"https:\/\/springdoc.cn\/spring-boot\/\">https:\/\/springdoc.cn\/spring-boot\/<\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"4_%E2%80%9CHello_world%E2%80%9D_%E4%BD%93%E9%AA%8C\"><\/span>4 \u201cHello world\u201d \u4f53\u9a8c<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u521b\u5efa\u4e00\u4e2a Spring Boot \u9879\u76ee\uff0c\u641c\u7d22\u6dfb\u52a0 Spring Web \u4f9d\u8d56<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713269149240.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 621px; --smush-placeholder-aspect-ratio: 621\/614;\" \/><\/p>\n<p>\u76f4\u63a5\u8fd0\u884c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713266447378.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1622px; --smush-placeholder-aspect-ratio: 1622\/769;\" \/><\/p>\n<p>\u6d4f\u89c8\u5668\u8bbf\u95ee\u672c\u673a 8080 \u7aef\u53e3\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u9519\u8bef\u9875\u9762\uff0c\u4f46\u662f\u786e\u5b9e\u8fd0\u884c\u8d77\u6765\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713266479313.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 718px; --smush-placeholder-aspect-ratio: 718\/249;\" \/><\/p>\n<hr \/>\n<p>\u4e00\u822c\u7684 Spring Boot \u9879\u76ee\u7ed3\u6784<\/p>\n<pre><code>myproject\/\n\u251c\u2500\u2500 src\/\n\u2502   \u251c\u2500\u2500 main\/\n\u2502   \u2502   \u251c\u2500\u2500 java\/\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 com\/\n\u2502   \u2502   \u2502       \u2514\u2500\u2500 example\/\n\u2502   \u2502   \u2502           \u251c\u2500\u2500 controllers\/       # \u5b58\u653e\u63a7\u5236\u5668\u7c7b\n\u2502   \u2502   \u2502           \u251c\u2500\u2500 models\/            # \u5b58\u653e\u6a21\u578b\u7c7b\n\u2502   \u2502   \u2502           \u251c\u2500\u2500 repositories\/      # \u5b58\u653e\u6570\u636e\u8bbf\u95ee\u5c42\u63a5\u53e3\n\u2502   \u2502   \u2502           \u251c\u2500\u2500 services\/          # \u5b58\u653e\u670d\u52a1\u5c42\u63a5\u53e3\u548c\u5b9e\u73b0\u7c7b\n\u2502   \u2502   \u2502           \u251c\u2500\u2500 utilities\/         # \u5b58\u653e\u5de5\u5177\u7c7b\n\u2502   \u2502   \u2502           \u2514\u2500\u2500 Application.java   # \u9879\u76ee\u7684\u5165\u53e3\u7c7b\n\u2502   \u2502   \u251c\u2500\u2500 resources\/\n\u2502   \u2502   \u2502   \u251c\u2500\u2500 application.properties     # \u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\u6587\u4ef6\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 static\/                    # \u5b58\u653e\u9759\u6001\u8d44\u6e90\u6587\u4ef6\n\u2502   \u2502   \u2514\u2500\u2500 webapp\/                        # \u5b58\u653eWeb\u5e94\u7528\u7a0b\u5e8f\u8d44\u6e90\uff08\u53ef\u9009\uff09\n\u2502   \u2514\u2500\u2500 test\/\n\u2502       \u251c\u2500\u2500 java\/\n\u2502       \u2502   \u2514\u2500\u2500 com\/\n\u2502       \u2502       \u2514\u2500\u2500 example\/\n\u2502       \u2502           \u2514\u2500\u2500 tests\/            # \u5b58\u653e\u6d4b\u8bd5\u7c7b\n\u2502       \u2514\u2500\u2500 resources\/                    # \u5b58\u653e\u6d4b\u8bd5\u8d44\u6e90\u6587\u4ef6\n\u2514\u2500\u2500 pom.xml                               # Maven\u9879\u76ee\u914d\u7f6e\u6587\u4ef6<\/code><\/pre>\n<ul>\n<li>src\/main\/java\uff1a\u5b58\u653eJava\u6e90\u4ee3\u7801\u7684\u6839\u76ee\u5f55\u3002<\/li>\n<li>src\/main\/java\/com\/example\/controllers\uff1a\u5b58\u653e\u63a7\u5236\u5668\u7c7b\uff0c\u5904\u7406HTTP\u8bf7\u6c42\u548c\u54cd\u5e94\u3002<\/li>\n<li>src\/main\/java\/com\/example\/models\uff1a\u5b58\u653e\u6a21\u578b\u7c7b\uff0c\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u7ed3\u6784\u3002<\/li>\n<li>src\/main\/java\/com\/example\/repositories\uff1a\u5b58\u653e\u6570\u636e\u8bbf\u95ee\u5c42\u63a5\u53e3\uff0c\u7528\u4e8e\u4e0e\u6570\u636e\u5e93\u6216\u5176\u4ed6\u6570\u636e\u6e90\u8fdb\u884c\u4ea4\u4e92\u3002<\/li>\n<li>src\/main\/java\/com\/example\/services\uff1a\u5b58\u653e\u670d\u52a1\u5c42\u63a5\u53e3\u548c\u5b9e\u73b0\u7c7b\uff0c\u5904\u7406\u4e1a\u52a1\u903b\u8f91\u3002<\/li>\n<li>src\/main\/java\/com\/example\/utilities\uff1a\u5b58\u653e\u5de5\u5177\u7c7b\uff0c\u63d0\u4f9b\u8f85\u52a9\u529f\u80fd\u3002<\/li>\n<li>src\/main\/resources\uff1a\u5b58\u653e\u9879\u76ee\u7684\u8d44\u6e90\u6587\u4ef6\uff0c\u5982\u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\u6587\u4ef6\u3001\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u7b49\u3002<\/li>\n<li>src\/main\/webapp\uff1a\u5982\u679c\u4f7f\u7528\u4f20\u7edf\u7684Web\u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u65b9\u5f0f\uff0c\u8be5\u76ee\u5f55\u5b58\u653eWeb\u5e94\u7528\u7a0b\u5e8f\u8d44\u6e90\uff08\u4f8b\u5982JSP\u6587\u4ef6\uff09\u3002<\/li>\n<li>src\/test\uff1a\u5b58\u653e\u6d4b\u8bd5\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<li>pom.xml\uff1aMaven\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8e\u5b9a\u4e49\u9879\u76ee\u7684\u4f9d\u8d56\u548c\u6784\u5efa\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u4e0a\u9762\u76f4\u63a5\u8fd0\u884c\uff0c\u8bbf\u95ee\u9875\u9762\u662f\u4e2a\u9519\u8bef\u9875\u5c31\u662f\u56e0\u4e3a\u7f3a\u5c11 controller \u6765\u5904\u7406\u8bf7\u6c42<br \/>\n\u73b0\u5728\u521b\u5efa\u4e00\u4e2a<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713267886090.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 364px; --smush-placeholder-aspect-ratio: 364\/186;\" \/><\/p>\n<pre><code class=\"language-java\">package com.iyatt.test1.controllers;\n\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class Test1Controller\n{\n    @RequestMapping(&quot;\/&quot;) \/\/ \u5904\u7406 http:\/\/IP:8080\/ \u5730\u5740\u7684\u8bf7\u6c42\n    public String hello()\n    {\n        return &quot;Hello World&quot;;\n    }\n}<\/code><\/pre>\n<p>\u518d\u8fd0\u884c Test1Application \u540e\u8bbf\u95ee\u53ef\u4ee5\u770b\u5230 Hello world<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713267989543.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 382px; --smush-placeholder-aspect-ratio: 382\/125;\" \/><\/p>\n<h1><span class=\"ez-toc-section\" id=\"5_%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\"><\/span>5 \u914d\u7f6e\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"51_%E5%85%AC%E5%85%B1%E5%BA%94%E7%94%A8%E5%B1%9E%E6%80%A7\"><\/span>5.1 \u516c\u5171\u5e94\u7528\u5c5e\u6027<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>application.properties \u5c31\u662f\u914d\u7f6e\u6587\u4ef6\uff0c\u53e6\u5916\u652f\u6301\u7528 yaml \u683c\u5f0f\u914d\u7f6e\uff0c\u5373\u547d\u540d\u4e3a application.yaml<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275272645.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 368px; --smush-placeholder-aspect-ratio: 368\/289;\" \/><\/p>\n<p>\u5b98\u65b9\u6587\u6863\u6709\u5173\u4e8e\u516c\u5171\u5e94\u7528\u5c5e\u6027\u7684\u8bf4\u660e\uff1a<a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/application-properties.html\">https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/application-properties.html<\/a><br \/>\n\u6bd4\u5982 server.port \u8bbe\u7f6e\u7aef\u53e3\uff0c\u9ed8\u8ba4\u662f 8080<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275435582.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 848px; --smush-placeholder-aspect-ratio: 848\/79;\" \/><br \/>\n\u6211\u8bbe\u7f6e\u7aef\u53e3\u4e3a 80\uff0c\u5373 http \u7684\u9ed8\u8ba4\u7aef\u53e3\uff0c\u8fd9\u6837\u6d4f\u89c8\u5668\u5c31\u53ef\u4ee5\u4e0d\u7528\u6307\u5b9a\u7aef\u53e3\u8fdb\u884c\u8bbf\u95ee<br \/>\n\u5728 application.properties \u4e2d\u6dfb\u52a0<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275528173.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 335px; --smush-placeholder-aspect-ratio: 335\/90;\" \/><br \/>\n\u8fd9\u6837\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528 IP \u8bbf\u95ee\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275556944.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 238px; --smush-placeholder-aspect-ratio: 238\/108;\" \/><\/p>\n<p>\u628a\u4e0a\u9762\u8bbe\u7f6e\u7684\u7aef\u53e3\u6ce8\u91ca\u6389\uff0c\u521b\u5efa application.yaml \u6587\u4ef6\uff0c\u5199\u5165<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275656014.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 311px; --smush-placeholder-aspect-ratio: 311\/87;\" \/><br \/>\n\u73b0\u5728\u53ef\u4ee5\u901a\u8fc7 81 \u7aef\u53e3\u8bbf\u95ee<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275713522.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 266px; --smush-placeholder-aspect-ratio: 266\/113;\" \/><\/p>\n<p>\u90a3\u4e48\u5982\u679c\u4e24\u79cd\u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u540c\u65f6\u5b58\u5728\uff0c\u4e14\u5bf9\u540c\u4e00\u4e2a\u53c2\u6570\u8bbe\u7f6e\u4e86\u4e0d\u540c\u503c\u4f18\u5148\u7ea7\u5982\u4f55\uff1f<br \/>\n\u628a properties \u8bbe\u7f6e\u7aef\u53e3\u4e3a 80\uff0cyaml \u8bbe\u7f6e\u7aef\u53e3\u4e3a 81\uff0c\u518d\u8fd0\u884c<br \/>\n\u53ef\u4ee5\u770b\u5230\u5b9e\u9645\u8fd0\u884c\u7684\u662f 80\uff0c\u4ee3\u8868 properties \u7684\u4f18\u5148\u7ea7\u66f4\u9ad8<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713275862452.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1386px; --smush-placeholder-aspect-ratio: 1386\/328;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"52_%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\"><\/span>5.2 \u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd9\u91cc\u4ee5 YAML \u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u6f14\u793a<\/p>\n<p>YAML \u7684\u8bed\u6cd5\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/yaml.org\/spec\/\">https:\/\/yaml.org\/spec\/<\/a><br \/>\n\u76ee\u524d\u6700\u65b0\u7684\u4e00\u7248\u662f 2021-10-01 \u7684 1.2.2 \u7248\u672c<\/p>\n<p>application.yaml \u5199\u5165\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-yaml\">name: Xiao Qiang\n\n# \u5bf9\u8c61\nperson:\n    name: ${name} # \u5f15\u7528\n    age: 18\n    adult: true\n\n# \u6570\u7ec4\naddress:\n    - Chong Qing\n    - Beijing\n\nmsg1: &#039;hello\\n world&#039; # \u4fdd\u7559\u539f\u59cb\u5b57\u7b26\u4e32\nmsg2: &quot;hello\\n world&quot; # \u7279\u6b8a\u5b57\u7b26\u4f1a\u8f6c\u4e49<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"521_%E9%80%90%E4%B8%AA%E8%AF%BB%E5%8F%96\"><\/span>5.2.1 \u9010\u4e2a\u8bfb\u53d6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-java\">package com.iyatt.test1.controllers;\n\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class Test1Controller\n{\n    @Value(&quot;${name}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684name\u5c5e\u6027\n    private String name;\n\n    @RequestMapping(&quot;\/name&quot;) \/\/ \u8bbf\u95ee http:\/\/localhost\/name \u83b7\u53d6name\u5c5e\u6027\u503c\n    public String get_name()\n    {\n        return this.name;\n    }\n\n    @Value(&quot;${person.name}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684person.name\u5c5e\u6027\n    private String person_name;\n\n    @Value(&quot;${person.age}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684person.age\u5c5e\u6027\n    private Integer person_age;\n\n    @Value(&quot;${person.adult}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684person.adult\u5c5e\u6027\n    private boolean person_adult;\n\n    @RequestMapping(&quot;\/person&quot;) \/\/ \u8bbf\u95ee http:\/\/localhost\/person \u83b7\u53d6person\u5bf9\u8c61\n    public String get_person()\n    {\n        return &quot;Name: &quot; + this.person_name + &quot;, Age: &quot; + this.person_age + &quot;, Adult: &quot; + this.person_adult;\n    }\n\n    @Value(&quot;${address[0]}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684address\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\n    private String address1;\n\n    @Value(&quot;${address[1]}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684address\u6570\u7ec4\u7b2c\u4e8c\u4e2a\u5143\u7d20\n    private String address2;\n\n    @RequestMapping(&quot;\/address&quot;) \/\/ \u8bbf\u95ee http:\/\/localhost\/address \u83b7\u53d6address\u6570\u7ec4\n    public String get_address()\n    {\n        return &quot;Address1: &quot; + this.address1 + &quot;, Address2: &quot; + this.address2;\n    }\n\n    @Value(&quot;${msg1}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684msg1\u5c5e\u6027\n    private String msg1;\n\n    @Value(&quot;${msg2}&quot;) \/\/ \u8bfb\u53d6application.yaml\u4e2d\u7684msg2\u5c5e\u6027\n    private String msg2;\n\n    @RequestMapping(&quot;\/msg&quot;) \/\/ \u8bbf\u95ee http:\/\/localhost\/msg \u83b7\u53d6msg\u6570\u7ec4\n    public String get_msg()\n    {\n        return &quot;msg1: &quot; + this.msg1 + &quot; msg2: &quot; + this.msg2;\n    }\n}<\/code><\/pre>\n<p>\u5206\u522b\u8bbf\u95ee<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713288475856.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 282px; --smush-placeholder-aspect-ratio: 282\/127;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713288490705.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 358px; --smush-placeholder-aspect-ratio: 358\/125;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713288579829.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 337px; --smush-placeholder-aspect-ratio: 337\/111;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713288600769.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 332px; --smush-placeholder-aspect-ratio: 332\/112;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"522_%E6%8C%89%E9%9C%80%E8%8E%B7%E5%8F%96\"><\/span>5.2.2 \u6309\u9700\u83b7\u53d6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u9700\u8981\u50cf\u4e0a\u9762\u90a3\u79cd\u9010\u4e2a\u8bfb\u53d6\u503c\u5230\u53d8\u91cf\u4e2d\uff0c\u53ef\u4ee5\u6574\u4f53\u52a0\u8f7d\uff0c\u7136\u540e\u6309\u9700\u8981\u83b7\u53d6\u5c5e\u6027\u503c<\/p>\n<pre><code class=\"language-java\">package com.iyatt.test1.controllers;\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.core.env.Environment;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class Test1Controller\n{\n    @Autowired\n    private Environment env;\n\n    @RequestMapping(&quot;\/&quot;) \/\/ \u8bbf\u95ee http:\/\/localhost\n    public String get_env()\n    {\n        return &quot;name: &quot; + env.getProperty(&quot;name&quot;) +\n                &quot;, person.name: &quot; + env.getProperty(&quot;person.name&quot;) +\n                &quot;,  person.age: &quot; + env.getProperty(&quot;person.age&quot;) +\n                &quot;, person.adult: &quot; + env.getProperty(&quot;person.adult&quot;) +\n                &quot;, adddress1: &quot; + env.getProperty(&quot;address[0]&quot;) +\n                &quot;, address2: &quot; + env.getProperty(&quot;address[1]&quot;) +\n                &quot;, msg1: &quot; + env.getProperty(&quot;msg1&quot;) +\n                &quot;, msg2: &quot; + env.getProperty(&quot;msg2&quot;);\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713314058229.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1256px; --smush-placeholder-aspect-ratio: 1256\/95;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"523_%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96\"><\/span>5.2.3 \u53cd\u5e8f\u5217\u5316<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u76f4\u63a5\u5c06\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u52a0\u8f7d\u5230\u5bf9\u8c61<br \/>\nBean \u901a\u7528\u65b9\u6cd5\u81ea\u52a8\u751f\u6210\uff0c\u53c2\u8003\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=14637\">https:\/\/blog.iyatt.com\/?p=14637<\/a><\/p>\n<p>application.yaml \u6539\u4e3a<\/p>\n<pre><code class=\"language-yaml\">person:\n    name: Xiao Wang\n    age: 18\n    adult: true\n    address:\n        - Chong Qing\n        - Beijing<\/code><\/pre>\n<p>\u521b\u5efa\u4e00\u4e2a Person.java<\/p>\n<pre><code class=\"language-java\">package com.iyatt.test1;\n\nimport org.springframework.boot.context.properties.ConfigurationProperties;\nimport org.springframework.stereotype.Component;\n\nimport lombok.Data;\n\n@Component\n@ConfigurationProperties(prefix = &quot;person&quot;) \/\/ \u8bfb\u53d6 person \u5bf9\u8c61\n@Data \/\/ \u81ea\u52a8\u751f\u6210 Baen \u901a\u7528\u65b9\u6cd5\npublic class Person\n{\n    private String name;\n    private Integer age;\n    private boolean adult;\n    private String[] address;\n}<\/code><\/pre>\n<p>controller.java<\/p>\n<pre><code class=\"language-java\">package com.iyatt.test1;\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class Test1Controller\n{\n    @Autowired\n    private Person person;\n\n    @RequestMapping(&quot;\/person&quot;)\n    public String get_person()\n    {\n        return person.toString();\n    }\n}<\/code><\/pre>\n<p>\u8fd0\u884c\u8bbf\u95ee<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713330444772.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 634px; --smush-placeholder-aspect-ratio: 634\/113;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"53_%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%88%86%E7%B1%BB\"><\/span>5.3 \u914d\u7f6e\u6587\u4ef6\u5206\u7c7b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"531_%E5%A4%9A%E6%96%87%E4%BB%B6\"><\/span>5.3.1 \u591a\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>application \u4f5c\u4e3a\u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u4e00\u822c\u6d4b\u8bd5\u73af\u5883\u7684\u914d\u7f6e\u6587\u4ef6\u547d\u540d\u4e3a application-test\uff0c\u5f00\u53d1\u73af\u5883\u547d\u540d\u4e3a application-dev\uff0c\u751f\u4ea7\u73af\u5883\u547d\u540d\u4e3a application-pro\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713332703724.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 180px; --smush-placeholder-aspect-ratio: 180\/154;\" \/><\/p>\n<p>\u6bd4\u5982\u6211\u5728 dev\u3001pro\u3001test \u5206\u522b\u8bbe\u7f6e\u670d\u52a1\u7aef\u53e3\u4e3a80\u300181\u300182<br \/>\n\u5728 application.properties \u63a7\u5236\u5f53\u524d\u7684\u6fc0\u6d3b\u73af\u5883\uff08\u540e\u7f00\uff09\u4e3a pro<\/p>\n<pre><code class=\"language-properties\">spring.profiles.active=pro<\/code><\/pre>\n<p>\u8fd0\u884c\u670d\u52a1\u5c31\u662f pro \u914d\u7f6e\u7684 81 \u7aef\u53e3\u542f\u7528\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713332842636.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 373px; --smush-placeholder-aspect-ratio: 373\/27;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"532_%E5%8D%95%E6%96%87%E4%BB%B6%E5%88%86%E6%AE%B5\"><\/span>5.3.2 \u5355\u6587\u4ef6\u5206\u6bb5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>application.yaml<\/p>\n<pre><code class=\"language-yaml\">---\nServer:\n  port: 80\n\nspring:\n    config:\n        activate: \n            on-profile: dev\n---\nServer:\n  port: 81\n\nspring:\n    config:\n        activate: \n            on-profile: pro\n---\nServer:\n  port: 82\n\nspring:\n    config:\n        activate: \n            on-profile: test\n---\nspring:\n    profiles:\n        active: test # \u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\u7684\u914d\u7f6e<\/code><\/pre>\n<p>test \u8bbe\u7f6e\u7684 82 \u7aef\u53e3\u8fd0\u884c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713334173229.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 378px; --smush-placeholder-aspect-ratio: 378\/29;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"533_%E8%BF%90%E8%A1%8C%E6%97%B6%E6%8C%87%E5%AE%9A%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\"><\/span>5.3.3 \u8fd0\u884c\u65f6\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6267\u884c\u547d\u4ee4\u6253\u5305<\/p>\n<pre><code>mvn package<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713335915195.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 290px; --smush-placeholder-aspect-ratio: 290\/630;\" \/><\/p>\n<p>\u8fd0\u884c\u5728 target \u76ee\u5f55\u4e0b\u7684 jar \u6587\u4ef6\uff0c\u5e76\u5728\u540e\u65b9\u901a\u8fc7\u53c2\u6570\u6307\u5b9a<\/p>\n<pre><code>java -jar .\\target\\test2-profile-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev<\/code><\/pre>\n<p>\u6bd4\u5982\u6211\u8fd9\u91cc\u6307\u5b9a\u4e3a dev \u8fd0\u884c\uff0c\u5c31\u4f1a\u4ee5 80 \u7aef\u53e3\u8fd0\u884c\uff08\u5373\u4f7f\u6587\u4ef6\u91cc\u6307\u5b9a\u7684\u662f test\uff09<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/04\/image-1713336021961.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 402px; --smush-placeholder-aspect-ratio: 402\/30;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"54_%E5%A4%96%E9%83%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6\"><\/span>5.4 \u5916\u90e8\u914d\u7f6e\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/features.html#features.external-config\">https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/features.html#features.external-config<\/a><\/p>\n<p>\u524d\u9762\u8bf4\u7684 application \u914d\u7f6e\u6587\u4ef6\u5728\u6253\u5305\u7684\u65f6\u5019\u4f1a\u4e00\u8d77\u6253\u5305\uff0c\u5982\u679c\u5728\u8fd0\u884c\u7684\u65f6\u5019\u60f3\u8981\u4fee\u6539\uff0c\u53ef\u4ee5\u6309\u7167\u540c\u6837\u7684\u683c\u5f0f\u7f16\u8f91\u4f5c\u4e3a\u5916\u90e8\u914d\u7f6e\u6587\u4ef6\uff0c\u5728\u8fd0\u884c\u7684\u65f6\u5019\u6307\u5b9a\u6216\u8005\u653e\u7f6e\u5230\u9ed8\u8ba4\u81ea\u52a8\u52a0\u8f7d\u7684\u8def\u5f84\uff0c\u4f1a\u8986\u76d6\u6253\u5305\u7684\u914d\u7f6e\u6587\u4ef6\u8d77\u4f5c\u7528\u3002\u53ef\u653e\u7f6e\u7684\u4f4d\u7f6e\u633a\u591a\u7684\uff0c\u9700\u8981\u7528\u7684\u65f6\u5019\u53ef\u4ee5\u73b0\u67e5\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 \u524d\u8a00 \u53bb\u5e74\u63a5\u8fc7\u4e00\u4e2a Java \u7684\u5355\u5b50\uff0c\u73b0\u5b66\u4e86 Java\uff08https:\/\/blog.iyatt.com\/?p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,585],"tags":[],"class_list":["post-14593","post","type-post","status-publish","format-standard","hentry","category-all","category-spring"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/14593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14593"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/14593\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}