{"id":69940,"date":"2026-02-01T07:41:24","date_gmt":"2026-01-31T23:41:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69940.html"},"modified":"2026-02-01T07:41:24","modified_gmt":"2026-01-31T23:41:24","slug":"nacos-%e9%85%8d%e7%bd%ae%e4%b8%ad%e5%bf%83","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69940.html","title":{"rendered":"Nacos-\u914d\u7f6e\u4e2d\u5fc3"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:0px\">\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E7%A4%BA%E6%84%8F%E5%9B%BE-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u4e2d\u5fc3\u793a\u610f\u56fe<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u4e2d\u5fc3-\u57fa\u672c\u4f7f\u7528<\/p>\n<p id=\"%E6%AD%A5%E9%AA%A4%E4%B8%80%EF%BC%9A%E5%90%AF%E5%8A%A8nacos-toc\" style=\"margin-left:40px\">\u6b65\u9aa4\u4e00&#xff1a;\u542f\u52a8nacos<\/p>\n<p id=\"%E6%AD%A5%E9%AA%A4%E4%BA%8C%EF%BC%9A%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96-toc\" style=\"margin-left:40px\">\u6b65\u9aa4\u4e8c&#xff1a;\u5f15\u5165\u4f9d\u8d56<\/p>\n<p id=\"%E6%AD%A5%E9%AA%A4%E4%B8%89%EF%BC%9Aapplication.properties%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:40px\">\u6b65\u9aa4\u4e09&#xff1a;application.properties\u914d\u7f6e<\/p>\n<p id=\"%E6%AD%A5%E9%AA%A4%E5%9B%9B%EF%BC%9A%E5%88%9B%E5%BB%BAdata-id(%E6%95%B0%E6%8D%AE%E9%9B%86)-toc\" style=\"margin-left:40px\">\u6b65\u9aa4\u56db&#xff1a;\u521b\u5efadata-id(\u6570\u636e\u96c6)<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E5%8A%A8%E6%80%81%E5%88%B7%E6%96%B0-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u4e2d\u5fc3-\u52a8\u6001\u5237\u65b0<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E9%85%8D%E7%BD%AE%E7%9B%91%E5%90%AC-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u4e2d\u5fc3-\u914d\u7f6e\u76d1\u542c<\/p>\n<p id=\"%E6%80%9D%E8%80%83%EF%BC%9ANacos%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E9%9B%86%E5%92%8Capplication.properties%E6%9C%89%E7%9B%B8%E5%90%8C%E7%9A%84%E9%85%8D%E7%BD%AE%EF%BC%8C%E9%82%A3%E4%B8%AA%E7%94%9F%E6%95%88%EF%BC%9F-toc\" style=\"margin-left:0px\">\u601d\u8003&#xff1a;Nacos\u4e2d\u7684\u6570\u636e\u96c6\u548capplication.properties\u6709\u76f8\u540c\u7684\u914d\u7f6e&#xff0c;\u90a3\u4e2a\u751f\u6548&#xff1f;<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E6%95%B0%E6%8D%AE%E9%9A%94%E7%A6%BB-toc\" style=\"margin-left:0px\">\u914d\u7f6e\u4e2d\u5fc3-\u6570\u636e\u9694\u79bb<\/p>\n<p id=\"namespace%E5%8C%BA%E5%88%86%E5%A4%9A%E7%8E%AF%E5%A2%83-toc\" style=\"margin-left:40px\">namespace\u533a\u5206\u591a\u73af\u5883<\/p>\n<p id=\"%E9%9C%80%E6%B1%82%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u9700\u6c42\u63cf\u8ff0<\/p>\n<p id=\"%E9%9A%BE%E7%82%B9-toc\" style=\"margin-left:80px\">\u96be\u70b9<\/p>\n<p id=\"%E5%8A%A8%E6%80%81%E5%88%87%E6%8D%A2%E7%8E%AF%E5%A2%83-toc\" style=\"margin-left:40px\">\u52a8\u6001\u5207\u6362\u73af\u5883<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u603b\u7ed3<\/p>\n<p id=\"%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83-toc\" style=\"margin-left:40px\">\u6ce8\u518c\u4e2d\u5fc3<\/p>\n<p id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-toc\" style=\"margin-left:40px\">\u914d\u7f6e\u4e2d\u5fc3<\/p>\n<\/p>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E7%A4%BA%E6%84%8F%E5%9B%BE\">\u914d\u7f6e\u4e2d\u5fc3\u793a\u610f\u56fe<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"444\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931f50fc2.png\" width=\"1083\" \/><\/p>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8\">\u914d\u7f6e\u4e2d\u5fc3-\u57fa\u672c\u4f7f\u7528<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"408\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931f8f1c8.png\" width=\"1124\" \/><\/p>\n<h3 id=\"%E6%AD%A5%E9%AA%A4%E4%B8%80%EF%BC%9A%E5%90%AF%E5%8A%A8nacos\">\u6b65\u9aa4\u4e00&#xff1a;\u542f\u52a8nacos<\/h3>\n<p>\u8be6\u7ec6\u64cd\u4f5c\u53ef\u4ee5\u770b\u6211\u524d\u51e0\u7bc7\u6587\u7ae0nacos-\u6ce8\u518c\u4e2d\u5fc3\u3001\u670d\u52a1\u6ce8\u518c<\/p>\n<h3 id=\"%E6%AD%A5%E9%AA%A4%E4%BA%8C%EF%BC%9A%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96\">\u6b65\u9aa4\u4e8c&#xff1a;\u5f15\u5165\u4f9d\u8d56<\/h3>\n<p>\u5728services\u7684pom\u6587\u4ef6\u5f15\u5165\u4f9d\u8d56&#xff1a;<\/p>\n<p>&lt;!&#8211;        \u5f15\u5165\u914d\u7f6e\u4e2d\u5fc3\u4f9d\u8d56&#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-config&lt;\/artifactId&gt;<br \/>\n        &lt;\/dependency&gt; <\/p>\n<h3 id=\"%E6%AD%A5%E9%AA%A4%E4%B8%89%EF%BC%9Aapplication.properties%E9%85%8D%E7%BD%AE\">\u6b65\u9aa4\u4e09&#xff1a;application.properties\u914d\u7f6e<\/h3>\n<p>\u4ee5\u8ba2\u5355\u4e3a\u4f8b&#xff0c;\u9996\u5148\u5728service-order\u7684application.properties\u4e2d\u52a0\u5165\u4e00\u884c<\/p>\n<p>spring.config.import&#061;nacos:service-order.properties <\/p>\n<p>\u8868\u793a\u5728\u9879\u76ee\u542f\u52a8\u65f6\u5bfc\u5165service-order.properties&#xff0c;\u5e76\u5728service-order.properties\u91cc\u9762\u5199\u5165\u914d\u7f6e\u3002\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<p>spring.application.name&#061;service-order<br \/>\nserver.port&#061;8000<\/p>\n<p>spring.cloud.nacos.server-addr&#061;127.0.0.1:8848<\/p>\n<p>spring.config.import&#061;nacos:service-order.properties <\/p>\n<h3 id=\"%E6%AD%A5%E9%AA%A4%E5%9B%9B%EF%BC%9A%E5%88%9B%E5%BB%BAdata-id(%E6%95%B0%E6%8D%AE%E9%9B%86)\">\u6b65\u9aa4\u56db&#xff1a;\u521b\u5efadata-id(\u6570\u636e\u96c6)<\/h3>\n<p>\u4ee3\u7801\u6dfb\u52a0\u5b8c\u6210\u540e\u542f\u52a8\u9879\u76ee&#xff0c;\u6253\u5f00nacos\u914d\u7f6e\u7ba1\u7406\u7684\u914d\u7f6e\u5217\u8868<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"383\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931fd7465.png\" width=\"228\" \/><\/p>\n<p>\u65b0\u5efa\u4e00\u4e2a\u914d\u7f6e&#xff0c;\u540d\u5b57\u4e0e\u4e0a\u8ff0\u914d\u7f6e\u540d\u76f8\u540c&#xff0c;\u914d\u7f6e\u683c\u5f0f\u4e3aproperties,\u5199\u5165\u914d\u7f6e\u5185\u5bb9&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"882\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931fe32e5.png\" width=\"1908\" \/><\/p>\n<p>\u70b9\u51fb\u53d1\u5e03\u4e4b\u540e&#xff0c;\u5728\u914d\u7f6e\u7ba1\u7406\u754c\u9762\u5c31\u53ef\u4ee5\u770b\u5230\u4e00\u6761\u914d\u7f6e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"882\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234120-697e93209aed8.png\" width=\"1908\" \/><\/p>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u53ef\u4ee5\u5bf9\u5176\u505a\u4e00\u4e2a\u6d4b\u8bd5&#xff1a;\u5728service-order\u7684controller\u4e2d\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5&#xff0c;\u83b7\u53d6\u5e76\u8fd4\u56de\u914d\u7f6e\u7684\u503c&#xff1a;<\/p>\n<p>    &#064;Value(&#034;${order.timeout}&#034;)<br \/>\n    String orderTimeout ;<br \/>\n    &#064;Value(&#034;${order.auto-confirm}&#034;)<br \/>\n    String orderAutoConfirm;<\/p>\n<p>    \/**<br \/>\n     * \u8fd4\u56de\u83b7\u53d6\u914d\u7f6e\u7684\u503c<br \/>\n     * &#064;return<br \/>\n     *\/<br \/>\n    &#064;GetMapping(&#034;\/config&#034;)<br \/>\n    public String config(){<br \/>\n        return &#034;order.timeout:&#034; &#043; orderTimeout &#043; &#034; order.auto-confirm:&#034; &#043; orderAutoConfirm;<br \/>\n    } <\/p>\n<p>\u6d4b\u8bd5\u6548\u679c\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"146\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234121-697e93214daa8.png\" width=\"666\" \/><\/p>\n<p>\u63a5\u7740\u6211\u4eec\u4fee\u6539naocs\u91cc\u9762\u7684\u914d\u7f6e\u53c2\u6570&#xff0c;\u524d\u7aef\u91cd\u65b0\u8bbf\u95ee\u65f6&#xff0c;\u5e76\u4e0d\u80fd\u6539\u6210\u6211\u4eec\u65b0\u6539\u7684\u53c2\u6570\u503c&#xff0c;\u6b64\u65f6\u9700\u8981\u5728controller\u4e2d\u52a0\u5165&#064;RefreshScope\u6ce8\u89e3&#xff0c;\u4e4b\u540e\u5373\u53ef\u81ea\u52a8\u5237\u65b0&#xff0c;\u81ea\u884c\u6d4b\u8bd5&#xff0c;\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u8fd9\u6837\u914d\u7f6e\u4e4b\u540e\u5c31\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5237\u65b0\u3002<\/p>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E5%8A%A8%E6%80%81%E5%88%B7%E6%96%B0\">\u914d\u7f6e\u4e2d\u5fc3-\u52a8\u6001\u5237\u65b0<\/h2>\n<p>\u4e0a\u4e00\u4e2a\u65b9\u6cd5\u8be6\u7ec6\u63cf\u8ff0\u4e86\u6b65\u9aa4\u4e00\u7684\u5b9e\u73b0&#xff0c;\u63a5\u4e0b\u6765\u5bf9\u6b65\u9aa4\u4e8c\u8fdb\u884c\u63cf\u8ff0\u3002<\/p>\n<p>1.\u5728service-order\u65b0\u5efa\u4e00\u4e2aOrderProperties\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u914d\u7f6e\u6279\u91cf\u7ed1\u5b9a\u3002<\/p>\n<p>package com.atguigu.order.properties;<\/p>\n<p>import lombok.Data;<br \/>\nimport org.springframework.boot.context.properties.ConfigurationProperties;<br \/>\nimport org.springframework.stereotype.Component;<\/p>\n<p>&#064;Component<br \/>\n&#064;Data<br \/>\n&#064;ConfigurationProperties(prefix &#061; &#034;order&#034;)\/\/\u914d\u7f6e\u6279\u91cf\u7ed1\u5b9a\u5728nacos\u4e0b&#xff0c;\u53ef\u4ee5\u65e0\u9700&#064;RefreshScope\u5c31\u53ef\u5b9e\u73b0<br \/>\npublic class OrderProperties {<br \/>\n    String Timeout ;<br \/>\n    String AutoConfirm;<br \/>\n}<\/p>\n<p>2.\u4fee\u6539controller\u5c06\u83b7\u53d6\u5e76\u8fd4\u56de\u914d\u7f6e\u7684\u65b9\u6cd5&#xff0c;\u5e76\u5c06controller\u7684&#064;RefreshScope\u6ce8\u89e3\u6ce8\u6389\u3002<\/p>\n<p>\/\/    &#064;Value(&#034;${order.timeout}&#034;)<br \/>\n\/\/    String orderTimeout ;<br \/>\n\/\/    &#064;Value(&#034;${order.auto-confirm}&#034;)<br \/>\n\/\/    String orderAutoConfirm;<\/p>\n<p>    \/**<br \/>\n     * \u8fd4\u56de\u83b7\u53d6\u914d\u7f6e\u7684\u503c<br \/>\n     * &#064;return<br \/>\n     *\/<br \/>\n    &#064;GetMapping(&#034;\/config&#034;)<br \/>\n    public String config(){<br \/>\n        return &#034;order.timeout:&#034; &#043; orderProperties.getTimeout() &#043; &#034; order.auto-confirm:&#034; &#043; orderProperties.getAutoConfirm();<br \/>\n    } <\/p>\n<p>3.\u6d4b\u8bd5\u53d1\u73b0\u540c\u6837\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5237\u65b0\u3002<\/p>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E9%85%8D%E7%BD%AE%E7%9B%91%E5%90%AC\">\u914d\u7f6e\u4e2d\u5fc3-\u914d\u7f6e\u76d1\u542c<\/h2>\n<p>\u5728service-order\u4e2d\u7f16\u5199&#xff1a;<\/p>\n<p>    \/\/1.\u9879\u76ee\u542f\u52a8\u5c31\u76d1\u542c\u914d\u7f6e\u6587\u4ef6\u53d8\u5316<br \/>\n    \/\/2.\u53d1\u751f\u53d8\u5316\u540e\u62ff\u5230\u53d8\u5316\u503c<br \/>\n    \/\/3.\u53d1\u9001\u90ae\u4ef6<\/p>\n<p>    &#064;Bean<br \/>\n    ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager) {<br \/>\n        return args -&gt; {<br \/>\n            ConfigService configService &#061; nacosConfigManager.getConfigService();<br \/>\n            configService.addListener(&#034;order.properties&#034;, &#034;DEFAULT_GROUP&#034;, new Listener() {<br \/>\n                &#064;Override<br \/>\n                public Executor getExecutor() {<br \/>\n                    return Executors.newFixedThreadPool(4);<br \/>\n                }<\/p>\n<p>                &#064;Override<br \/>\n                public void receiveConfigInfo(String configInfo) {<br \/>\n                    System.out.println(&#034;\u53d8\u5316\u7684\u914d\u7f6e\u9879&#xff1a;&#034;&#043; configInfo);<br \/>\n                    System.out.println(&#034;\u53d1\u9001\u90ae\u4ef6&#034;);<br \/>\n                }<br \/>\n            });<br \/>\n            System.out.println(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#034;);<br \/>\n        };<br \/>\n    } <\/p>\n<p>\u9879\u76ee\u542f\u52a8\u5c31\u53ef\u4ee5\u76d1\u542c\u914d\u7f6e\u4e86\u3002<\/p>\n<h2 id=\"%E6%80%9D%E8%80%83%EF%BC%9ANacos%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E9%9B%86%E5%92%8Capplication.properties%E6%9C%89%E7%9B%B8%E5%90%8C%E7%9A%84%E9%85%8D%E7%BD%AE%EF%BC%8C%E9%82%A3%E4%B8%AA%E7%94%9F%E6%95%88%EF%BC%9F\">\u601d\u8003&#xff1a;Nacos\u4e2d\u7684\u6570\u636e\u96c6\u548capplication.properties\u6709\u76f8\u540c\u7684\u914d\u7f6e&#xff0c;\u90a3\u4e2a\u751f\u6548&#xff1f;<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"210\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234121-697e932158653.png\" width=\"837\" \/><\/p>\n<p>\u5148\u5bfc\u5165\u4f18\u5148\u3001\u5916\u90e8\u4f18\u5148<\/p>\n<h2 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83-%E6%95%B0%E6%8D%AE%E9%9A%94%E7%A6%BB\" style=\"background-color:transparent\">\u914d\u7f6e\u4e2d\u5fc3-\u6570\u636e\u9694\u79bb<\/h2>\n<h3 id=\"namespace%E5%8C%BA%E5%88%86%E5%A4%9A%E7%8E%AF%E5%A2%83\">namespace\u533a\u5206\u591a\u73af\u5883<\/h3>\n<h4 id=\"%E9%9C%80%E6%B1%82%E6%8F%8F%E8%BF%B0\">\u9700\u6c42\u63cf\u8ff0<\/h4>\n<p>1.\u9879\u76ee\u6709\u591a\u5957\u73af\u5883:dev,test,prod 2.\u6bcf\u4e2a\u5fae\u670d\u52a1&#xff0c;\u540c\u4e00\u79cd\u914d\u7f6e&#xff0c;\u5728\u6bcf\u5957\u73af\u5883\u7684\u503c\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n<ul>\n<li>\u5982:database.properties<\/li>\n<li>\u5982:common.properties<\/li>\n<\/ul>\n<p>3.\u9879\u76ee\u53ef\u4ee5\u901a\u8fc7\u5207\u6362\u73af\u5883&#xff0c;\u52a0\u8f7d\u672c\u73af\u5883\u7684\u914d\u7f6e<\/p>\n<h4 id=\"%E9%9A%BE%E7%82%B9\">\u96be\u70b9<\/h4>\n<ul>\n<li>\u533a\u5206\u591a\u5957\u73af\u5883<\/li>\n<li>\u533a\u5206\u591a\u79cd\u5fae\u670d\u52a1<\/li>\n<li>\u533a\u5206\u591a\u79cd\u914d\u7f6e<\/li>\n<li>\u6309\u9700\u52a0\u8f7d\u914d\u7f6e<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"888\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234121-697e932172f07.png\" width=\"1899\" \/><\/p>\n<p>\u5728nacos\u7684\u547d\u540d\u7a7a\u95f4\u65b0\u5efa\u4e00\u4e2a\u5f00\u53d1\u7684\u547d\u540d\u7a7a\u95f4<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"882\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234122-697e93221a32c.png\" width=\"1908\" \/><\/p>\n<p>\u521b\u5efa\u597d\u4e0d\u540c\u7684\u547d\u540d\u7a7a\u95f4\u4e4b\u540e&#xff0c;\u53ef\u4ee5\u5728\u914d\u7f6e\u7ba1\u7406\u4e2d\u914d\u7f6e\u4e0d\u540c\u547d\u540d\u7a7a\u95f4\u7684\u914d\u7f6e&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"882\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234122-697e9322a8122.png\" width=\"1908\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"468\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234123-697e932343904.png\" width=\"984\" \/><\/p>\n<h3 id=\"%E5%8A%A8%E6%80%81%E5%88%87%E6%8D%A2%E7%8E%AF%E5%A2%83\">\u52a8\u6001\u5207\u6362\u73af\u5883<\/h3>\n<p>1.\u5c06\u4e4b\u524dresources\u8def\u5f84\u4e0b\u7684application.properties\u91cc\u7684\u5185\u5bb9\u6ce8\u6389<\/p>\n<p>2.\u5728resources\u8def\u5f84\u4e0b\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6application.yml&#xff0c;\u5c06\u6240\u6709\u914d\u7f6e\u5199\u5230\u8fd9\u4e2a\u6587\u4ef6\u91cc\u3002<\/p>\n<p>server:<br \/>\n  port: 8000<br \/>\nspring:<br \/>\n  profiles:<br \/>\n    active: test<br \/>\n  application:<br \/>\n    name: server-order<br \/>\n  cloud:<br \/>\n    nacos:<br \/>\n      server-addr: 127.0.0.1:8848<br \/>\n      config:<br \/>\n        import-check:<br \/>\n          enabled: false<br \/>\n        namespace: ${spring.profiles.active:dev}<\/p>\n<p>&#8212;<br \/>\nspring:<br \/>\n  config:<br \/>\n    import:<br \/>\n      &#8211; nacos:common.properties?group&#061;order<br \/>\n      &#8211; nacos:database.properties?group&#061;order<br \/>\n    activate:<br \/>\n      on-profile: dev<br \/>\n&#8212;<br \/>\nspring:<br \/>\n  config:<br \/>\n    import:<br \/>\n      &#8211; nacos:common.properties?group&#061;order<br \/>\n      &#8211; nacos:database.properties?group&#061;order<br \/>\n      &#8211; nacos:haha.properties?group&#061;order<br \/>\n    activate:<br \/>\n      on-profile: test<\/p>\n<p>&#8212;<br \/>\nspring:<br \/>\n  config:<br \/>\n    import:<br \/>\n      &#8211; nacos:common.properties?group&#061;order<br \/>\n      &#8211; nacos:database.properties?group&#061;order<br \/>\n      &#8211; nacos:hehe.properties?group&#061;order<br \/>\n    activate:<br \/>\n      on-profile: prod<\/p>\n<p>\u9879\u76ee\u542f\u52a8\u4e4b\u540e&#xff0c;\u5373\u53ef\u5b9e\u73b0\u52a8\u6001\u5207\u6362\u73af\u5883\u3002<\/p>\n<h2 id=\"%E6%80%BB%E7%BB%93\">\u603b\u7ed3<\/h2>\n<h3 id=\"%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83\">\u6ce8\u518c\u4e2d\u5fc3<\/h3>\n<p> 1.\u5f15\u5165 spring-cloud-starter-alibaba-nacos-discovery\u4f9d\u8d56,\u914d\u7f6eNacos\u5730\u5740<\/p>\n<p>2.&#064;EnableDiscoveryClient \u5f00\u542f\u670d\u52a1\u53d1\u73b0\u529f\u80fd<\/p>\n<p>\u6269\u5c55 1.DiscoveryClient\u83b7\u53d6\u670d\u52a1\u5b9e\u4f8b\u5217\u8868<\/p>\n<p>2.LoadBalancerClient \u8d1f\u8f7d\u5747\u8861\u9009\u62e9\u4e00\u4e2a\u5b9e\u4f8b(\u9700\u8981\u5f15\u5165 spring-cloud-starter-loadbalancer)<\/p>\n<p>3.RestTemplate \u53ef\u4ee5\u53d1\u8d77\u8fdc\u7a0b\u8c03\u7528<\/p>\n<h3 id=\"%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83\">\u914d\u7f6e\u4e2d\u5fc3<\/h3>\n<p>1. \u5f15\u5165 spring-cloud-starter-alibaba-nacos-config\u4f9d\u8d56&#xff0c;\u914d\u7f6eNacos\u5730\u5740<\/p>\n<p>2. \u6dfb\u52a0\u6570\u636e\u96c6(data-id)&#xff0c;\u4f7f\u7528spring.config.import \u5bfc\u5165\u6570\u636e\u96c6<\/p>\n<p>3.&#064;Value &#043; &#064;RefreshScope \u53d6\u503c&#043;\u81ea\u52a8\u5237\u65b0<\/p>\n<p>4.&#064;ConfigurationProperties\u6279\u91cf\u7ed1\u5b9a\u81ea\u52a8\u5237\u65b0<\/p>\n<p>5.NacosConfigManager \u76d1\u542c\u914d\u7f6e\u53d8\u5316<\/p>\n<p>\u6269\u5c55:<\/p>\n<p>\u914d\u7f6e\u4f18\u5148\u7ea7;namespace\u533a\u5206\u73af\u5883\u3001group\u533a\u5206\u5fae\u670d\u52a1\u3001data-id\u533a\u5206\u914d\u7f6e<\/p>\n<p>\u5b9e\u73b0 \u6570\u636e\u9694\u79bb&#043;\u73af\u5883\u5207\u6362<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u914d\u7f6e\u4e2d\u5fc3\u793a\u610f\u56fe<br \/>\n\u914d\u7f6e\u4e2d\u5fc3-\u57fa\u672c\u4f7f\u7528<br \/>\n\u6b65\u9aa4\u4e00&#xff1a;\u542f\u52a8nacos<br \/>\n\u6b65\u9aa4\u4e8c&#xff1a;\u5f15\u5165\u4f9d\u8d56<br \/>\n\u6b65\u9aa4\u4e09&#xff1a;application.properties\u914d\u7f6e<br \/>\n\u6b65\u9aa4\u56db&#xff1a;\u521b\u5efadata-id(\u6570\u636e\u96c6)<br \/>\n\u914d\u7f6e\u4e2d\u5fc3-\u52a8\u6001\u5237\u65b0<br \/>\n\u914d\u7f6e\u4e2d\u5fc3-\u914d\u7f6e\u76d1\u542c<br \/>\n\u601d\u8003&#xff1a;Nacos\u4e2d\u7684\u6570\u636e\u96c6\u548capplication.properties\u6709\u76f8\u540c\u7684\u914d\u7f6e&#xff0c;\u90a3\u4e2a\u751f\u6548&#xff1f;<br \/>\n\u914d\u7f6e\u4e2d\u5fc3-\u6570\u636e\u9694\u79bb<br \/>\nnamespace\u533a\u5206\u591a<\/p>\n","protected":false},"author":2,"featured_media":69929,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7345,99,1864,87],"topic":[],"class_list":["post-69940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-7345","tag-java","tag-nacos","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/69940.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u914d\u7f6e\u4e2d\u5fc3\u793a\u610f\u56fe \u914d\u7f6e\u4e2d\u5fc3-\u57fa\u672c\u4f7f\u7528 \u6b65\u9aa4\u4e00&#xff1a;\u542f\u52a8nacos \u6b65\u9aa4\u4e8c&#xff1a;\u5f15\u5165\u4f9d\u8d56 \u6b65\u9aa4\u4e09&#xff1a;application.properties\u914d\u7f6e \u6b65\u9aa4\u56db&#xff1a;\u521b\u5efadata-id(\u6570\u636e\u96c6) \u914d\u7f6e\u4e2d\u5fc3-\u52a8\u6001\u5237\u65b0 \u914d\u7f6e\u4e2d\u5fc3-\u914d\u7f6e\u76d1\u542c \u601d\u8003&#xff1a;Nacos\u4e2d\u7684\u6570\u636e\u96c6\u548capplication.properties\u6709\u76f8\u540c\u7684\u914d\u7f6e&#xff0c;\u90a3\u4e2a\u751f\u6548&#xff1f; \u914d\u7f6e\u4e2d\u5fc3-\u6570\u636e\u9694\u79bb namespace\u533a\u5206\u591a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69940.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-31T23:41:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931f50fc2.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69940.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69940.html\",\"name\":\"Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-31T23:41:24+00:00\",\"dateModified\":\"2026-01-31T23:41:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69940.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69940.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69940.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Nacos-\u914d\u7f6e\u4e2d\u5fc3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/69940.html","og_locale":"zh_CN","og_type":"article","og_title":"Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u914d\u7f6e\u4e2d\u5fc3\u793a\u610f\u56fe \u914d\u7f6e\u4e2d\u5fc3-\u57fa\u672c\u4f7f\u7528 \u6b65\u9aa4\u4e00&#xff1a;\u542f\u52a8nacos \u6b65\u9aa4\u4e8c&#xff1a;\u5f15\u5165\u4f9d\u8d56 \u6b65\u9aa4\u4e09&#xff1a;application.properties\u914d\u7f6e \u6b65\u9aa4\u56db&#xff1a;\u521b\u5efadata-id(\u6570\u636e\u96c6) \u914d\u7f6e\u4e2d\u5fc3-\u52a8\u6001\u5237\u65b0 \u914d\u7f6e\u4e2d\u5fc3-\u914d\u7f6e\u76d1\u542c \u601d\u8003&#xff1a;Nacos\u4e2d\u7684\u6570\u636e\u96c6\u548capplication.properties\u6709\u76f8\u540c\u7684\u914d\u7f6e&#xff0c;\u90a3\u4e2a\u751f\u6548&#xff1f; \u914d\u7f6e\u4e2d\u5fc3-\u6570\u636e\u9694\u79bb namespace\u533a\u5206\u591a","og_url":"https:\/\/www.wsisp.com\/helps\/69940.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-31T23:41:24+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260131234119-697e931f50fc2.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69940.html","url":"https:\/\/www.wsisp.com\/helps\/69940.html","name":"Nacos-\u914d\u7f6e\u4e2d\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-31T23:41:24+00:00","dateModified":"2026-01-31T23:41:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69940.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69940.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69940.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Nacos-\u914d\u7f6e\u4e2d\u5fc3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=69940"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69940\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/69929"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69940"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}