詳解springcloud nacos使用

1.nacos server安裝

  1. 下載 Nacos Server 2.5.1 https://nacos.io/download/nacos-server/?spm=5238cd80.2ef5001f.0.0.3f613b7clM2t6D

部署文檔:https://nacos.io/docs/latest/manual/admin/deployment/deployment-standalone/?spm=5238cd80.6a33be36.0.0.25b41e5deZvu7d

2.安裝步驟

  1. 使用mysql數據庫,刷入nacos sql腳本:
/** Copyright 1999-2018 Alibaba Group Holding Ltd.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*//******************************************/
/*   表名稱 = config_info                  */
/******************************************/
CREATE TABLE `config_info` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',`data_id` varchar(255) NOT NULL COMMENT 'data_id',`group_id` varchar(128) DEFAULT NULL COMMENT 'group_id',`content` longtext NOT NULL COMMENT 'content',`md5` varchar(32) DEFAULT NULL COMMENT 'md5',`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間',`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',`src_user` text COMMENT 'source user',`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',`tenant_id` varchar(128) DEFAULT '' COMMENT '租戶字段',`c_desc` varchar(256) DEFAULT NULL COMMENT 'configuration description',`c_use` varchar(64) DEFAULT NULL COMMENT 'configuration usage',`effect` varchar(64) DEFAULT NULL COMMENT '配置生效的描述',`type` varchar(64) DEFAULT NULL COMMENT '配置的類型',`c_schema` text COMMENT '配置的模式',`encrypted_data_key` varchar(1024) NOT NULL DEFAULT '' COMMENT '密鑰',PRIMARY KEY (`id`),UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';/******************************************/
/*   表名稱 = config_info  since 2.5.0                */
/******************************************/
CREATE TABLE `config_info_gray` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',`data_id` varchar(255) NOT NULL COMMENT 'data_id',`group_id` varchar(128) NOT NULL COMMENT 'group_id',`content` longtext NOT NULL COMMENT 'content',`md5` varchar(32) DEFAULT NULL COMMENT 'md5',`src_user` text COMMENT 'src_user',`src_ip` varchar(100) DEFAULT NULL COMMENT 'src_ip',`gmt_create` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'gmt_create',`gmt_modified` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'gmt_modified',`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',`tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',`gray_name` varchar(128) NOT NULL COMMENT 'gray_name',`gray_rule` text NOT NULL COMMENT 'gray_rule',`encrypted_data_key` varchar(256) NOT NULL DEFAULT '' COMMENT 'encrypted_data_key',PRIMARY KEY (`id`),UNIQUE KEY `uk_configinfogray_datagrouptenantgray` (`data_id`,`group_id`,`tenant_id`,`gray_name`),KEY `idx_dataid_gmt_modified` (`data_id`,`gmt_modified`),KEY `idx_gmt_modified` (`gmt_modified`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='config_info_gray';/******************************************/
/*   表名稱 = config_tags_relation         */
/******************************************/
CREATE TABLE `config_tags_relation` (`id` bigint(20) NOT NULL COMMENT 'id',`tag_name` varchar(128) NOT NULL COMMENT 'tag_name',`tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',`data_id` varchar(255) NOT NULL COMMENT 'data_id',`group_id` varchar(128) NOT NULL COMMENT 'group_id',`tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',`nid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'nid, 自增長標識',PRIMARY KEY (`nid`),UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';/******************************************/
/*   表名稱 = group_capacity               */
/******************************************/
CREATE TABLE `group_capacity` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵ID',`group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整個集群',`quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配額,0表示使用默認值',`usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',`max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '單個配置大小上限,單位為字節,0表示使用默認值',`max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大個數,,0表示使用默認值',`max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '單個聚合數據的子配置大小上限,單位為字節,0表示使用默認值',`max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大變更歷史數量',`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間',`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`id`),UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';/******************************************/
/*   表名稱 = his_config_info              */
/******************************************/
CREATE TABLE `his_config_info` (`id` bigint(20) unsigned NOT NULL COMMENT 'id',`nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'nid, 自增標識',`data_id` varchar(255) NOT NULL COMMENT 'data_id',`group_id` varchar(128) NOT NULL COMMENT 'group_id',`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',`content` longtext NOT NULL COMMENT 'content',`md5` varchar(32) DEFAULT NULL COMMENT 'md5',`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間',`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',`src_user` text COMMENT 'source user',`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',`op_type` char(10) DEFAULT NULL COMMENT 'operation type',`tenant_id` varchar(128) DEFAULT '' COMMENT '租戶字段',`encrypted_data_key` varchar(1024) NOT NULL DEFAULT '' COMMENT '密鑰',`publish_type` varchar(50)  DEFAULT 'formal' COMMENT 'publish type gray or formal',`gray_name` varchar(50)  DEFAULT NULL COMMENT 'gray name',`ext_info`  longtext DEFAULT NULL COMMENT 'ext info',PRIMARY KEY (`nid`),KEY `idx_gmt_create` (`gmt_create`),KEY `idx_gmt_modified` (`gmt_modified`),KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租戶改造';/******************************************/
/*   表名稱 = tenant_capacity              */
/******************************************/
CREATE TABLE `tenant_capacity` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵ID',`tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',`quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配額,0表示使用默認值',`usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',`max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '單個配置大小上限,單位為字節,0表示使用默認值',`max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大個數',`max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '單個聚合數據的子配置大小上限,單位為字節,0表示使用默認值',`max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大變更歷史數量',`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間',`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',PRIMARY KEY (`id`),UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租戶容量信息表';CREATE TABLE `tenant_info` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',`kp` varchar(128) NOT NULL COMMENT 'kp',`tenant_id` varchar(128) default '' COMMENT 'tenant_id',`tenant_name` varchar(128) default '' COMMENT 'tenant_name',`tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',`create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',`gmt_create` bigint(20) NOT NULL COMMENT '創建時間',`gmt_modified` bigint(20) NOT NULL COMMENT '修改時間',PRIMARY KEY (`id`),UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';CREATE TABLE `users` (`username` varchar(50) NOT NULL PRIMARY KEY COMMENT 'username',`password` varchar(500) NOT NULL COMMENT 'password',`enabled` boolean NOT NULL COMMENT 'enabled'
);CREATE TABLE `roles` (`username` varchar(50) NOT NULL COMMENT 'username',`role` varchar(50) NOT NULL COMMENT 'role',UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);CREATE TABLE `permissions` (`role` varchar(50) NOT NULL COMMENT 'role',`resource` varchar(128) NOT NULL COMMENT 'resource',`action` varchar(8) NOT NULL COMMENT 'action',UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);
  1. 修改${nacos.home}/conf/application.properties文件,增加支持MySQL數據源配置,添加MySQL數據源的url、用戶名和密碼。
 spring.sql.init.platform=mysql### Count of DB:db.num=1### Connect URL of DB:db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghaidb.user.0=rootdb.password.0=123456
  1. 設置登錄賬戶密碼:
#開啟鑒權 
nacos.core.auth.enabled=true#設置服務端驗證 key
nacos.core.auth.server.identity.key=test
nacos.core.auth.server.identity.value=test#設置默認 token
# The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

4.啟動 nacos server ,windows下執行:

.\startup.cmd -m standalone 或者修改startup.cmd中mode=cluster為standalone 雙擊啟動

  1. 訪問地址:
    http://127.0.0.1:8848/nacos
    在這里插入圖片描述
    默認用戶密碼為 nacos nacos
    修改后賬戶密碼 nacos 123456

2.SpringCloud Nacos配置注冊中心報錯 Could not resolve placeholder xxx in value 原因分析:

springcloud阿里巴巴框架,讀取nacos配置中心變量值:
在這里插入圖片描述

出現異常錯誤:
2025-04-10T16:03:43.682+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[wemedia-oss-nacos] & group[DEFAULT_GROUP]
2025-04-10T16:03:43.689+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[wemedia-oss-nacos.properties] & group[DEFAULT_GROUP]
2025-04-10T16:03:43.694+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.c.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[wemedia-oss-nacos-dev.properties] & group[DEFAULT_GROUP]
2025-04-10T16:03:43.695+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name=‘bootstrapProperties-wemedia-oss-nacos-dev.properties,DEFAULT_GROUP’}, BootstrapPropertySource {name=‘bootstrapProperties-wemedia-oss-nacos.properties,DEFAULT_GROUP’}, BootstrapPropertySource {name=‘bootstrapProperties-wemedia-oss-nacos,DEFAULT_GROUP’}]
2025-04-10T16:03:43.698+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] c.a.nacos.client.logging.NacosLogging : Load Logback Configuration of Nacos fail, message: Could not initialize Logback Nacos logging from classpath:nacos-logback.xml
2025-04-10T16:03:43.698+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.wemedia.NacosApplication : The following 1 profile is active: “dev”
2025-04-10T16:03:44.034+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=a4be7677-4070-3c92-9fd3-af9028deafd6
2025-04-10T16:03:44.145+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8877 (http)
2025-04-10T16:03:44.151+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2025-04-10T16:03:44.151+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.16]
2025-04-10T16:03:44.178+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2025-04-10T16:03:44.178+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 471 ms
2025-04-10T16:03:45.386+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2025-04-10T16:03:46.486+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2025-04-10T16:03:46.495+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path ‘/actuator’
2025-04-10T16:03:46.528+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8877 (http) with context path ‘’
2025-04-10T16:03:46.530+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : initializer namespace from ans.namespace attribute : null
2025-04-10T16:03:46.530+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : initializer namespace from ALIBABA_ALIWARE_NAMESPACE attribute :null
2025-04-10T16:03:46.530+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : initializer namespace from namespace attribute :null
2025-04-10T16:03:46.537+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
2025-04-10T16:03:46.537+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.
2025-04-10T16:03:46.701+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [RpcClientFactory] create a new rpc client of f8596e2c-e91c-4966-a72a-ab099222d79e
2025-04-10T16:03:46.702+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] RpcClient init, ServerListFactory = com.alibaba.nacos.client.naming.core.ServerListManager
2025-04-10T16:03:46.702+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Registry connection listener to current client:com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService
2025-04-10T16:03:46.702+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Register server push request handler:com.alibaba.nacos.client.naming.remote.gprc.NamingPushRequestHandler
2025-04-10T16:03:46.702+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Try to connect to server on start up, server: {serverIp = ‘127.0.0.1’, server main port = 8848}
2025-04-10T16:03:46.702+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.c.remote.client.grpc.GrpcClient : grpc client connection server:127.0.0.1 ip,serverPort:9848,grpcTslConfig:{“sslProvider”:“OPENSSL”,“enableTls”:false,“mutualAuthEnable”:false,“trustAll”:false}
2025-04-10T16:03:46.814+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Success to connect to server [127.0.0.1:8848] on start up, connectionId = 1744272226706_127.0.0.1_4812
2025-04-10T16:03:46.814+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient C o n n e c t R e s e t R e q u e s t H a n d l e r 2025 ? 04 ? 10 T 16 : 03 : 46.814 + 08 : 00 I N F O 35784 ? ? ? [ w e m e d i a ? o s s ? n a c o s ] [ m a i n ] c o m . a l i b a b a . n a c o s . c o m m o n . r e m o t e . c l i e n t : [ f 8596 e 2 c ? e 91 c ? 4966 ? a 72 a ? a b 099222 d 79 e ] R e g i s t e r s e r v e r p u s h r e q u e s t h a n d l e r : c o m . a l i b a b a . n a c o s . c o m m o n . r e m o t e . c l i e n t . R p c C l i e n t ConnectResetRequestHandler 2025-04-10T16:03:46.814+08:00 INFO 35784 --- [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient ConnectResetRequestHandler2025?04?10T16:03:46.814+08:00INFO35784???[wemedia?oss?nacos][main]com.alibaba.nacos.common.remote.client:[f8596e2c?e91c?4966?a72a?ab099222d79e]Registerserverpushrequesthandler:com.alibaba.nacos.common.remote.client.RpcClient$Lambda/0x000001edb93fcc88
2025-04-10T16:03:46.814+08:00 INFO 35784 — [wemedia-oss-nacos] [t.remote.worker] com.alibaba.nacos.common.remote.client : [f8596e2c-e91c-4966-a72a-ab099222d79e] Notify connected event to listeners.
2025-04-10T16:03:46.814+08:00 INFO 35784 — [wemedia-oss-nacos] [t.remote.worker] com.alibaba.nacos.client.naming : Grpc connection connect
2025-04-10T16:03:46.814+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [REGISTER-SERVICE] public registering service wemedia-oss-nacos with instance Instance{instanceId=‘null’, ip=‘192.168.239.1’, port=8877, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName=‘DEFAULT’, serviceName=‘null’, metadata={IPv6=null, preserved.register.source=SPRING_CLOUD}}
2025-04-10T16:03:46.823+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP wemedia-oss-nacos 192.168.239.1:8877 register finished
2025-04-10T16:03:47.840+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2025-04-10T16:03:47.842+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘scopedTarget.nacosConfigClientController’: Injection of autowired dependencies failed
2025-04-10T16:03:47.844+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.registry.NacosServiceRegistry : De-registering from Nacos Server now…
2025-04-10T16:03:47.844+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [DEREGISTER-SERVICE] public deregistering service wemedia-oss-nacos with instance: Instance{instanceId=‘null’, ip=‘192.168.239.1’, port=8877, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName=‘DEFAULT’, serviceName=‘null’, metadata={}}
2025-04-10T16:03:47.859+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.c.n.registry.NacosServiceRegistry : De-registration finished.
2025-04-10T16:03:47.859+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.cache.ServiceInfoHolder do shutdown begin
2025-04-10T16:03:47.859+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.backups.FailoverReactor do shutdown begin
2025-04-10T16:03:48.182+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.backups.FailoverReactor do shutdown stop
2025-04-10T16:03:48.182+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.cache.ServiceInfoHolder do shutdown stop
2025-04-10T16:03:48.182+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate do shutdown begin
2025-04-10T16:03:48.182+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.core.ServiceInfoUpdateService do shutdown begin
2025-04-10T16:03:48.182+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.core.ServiceInfoUpdateService do shutdown stop
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.core.ServerListManager do shutdown begin
2025-04-10T16:03:48.183+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [NamingHttpClientManager] Start destroying NacosRestTemplate
2025-04-10T16:03:48.183+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [NamingHttpClientManager] Destruction of the end
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.core.ServerListManager do shutdown stop
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy do shutdown begin
2025-04-10T16:03:48.183+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [NamingHttpClientManager] Start destroying NacosRestTemplate
2025-04-10T16:03:48.183+08:00 WARN 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : [NamingHttpClientManager] Destruction of the end
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy do shutdown stop
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : Shutdown rpc client, set status to shutdown
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : Shutdown client event executor java.util.concurrent.ScheduledThreadPoolExecutor@431babe6[Running, pool size = 2, active threads = 2, queued tasks = 0, completed tasks = 0]
2025-04-10T16:03:48.183+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.common.remote.client : Close current connection 1744272226706_127.0.0.1_4812
2025-04-10T16:03:48.186+08:00 WARN 35784 — [wemedia-oss-nacos] [tor-127.0.0.1-9] c.a.n.c.remote.client.grpc.GrpcClient : [1744272226706_127.0.0.1_4812]Ignore error event,isRunning:false,isAbandon=false
2025-04-10T16:03:48.187+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.c.remote.client.grpc.GrpcClient : Shutdown grpc executor java.util.concurrent.ThreadPoolExecutor@2f73f0c7[Running, pool size = 10, active threads = 0, queued tasks = 0, completed tasks = 10]
2025-04-10T16:03:48.187+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : Shutdown grpc redo service executor java.util.concurrent.ScheduledThreadPoolExecutor@59e0d521[Running, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]
2025-04-10T16:03:48.187+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.c.a.r.identify.CredentialWatcher : [null] CredentialWatcher is stopped
2025-04-10T16:03:48.187+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] c.a.n.c.a.r.identify.CredentialService : [null] CredentialService is freed
2025-04-10T16:03:48.187+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] com.alibaba.nacos.client.naming : com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate do shutdown stop
2025-04-10T16:03:48.191+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2025-04-10T16:03:48.199+08:00 INFO 35784 — [wemedia-oss-nacos] [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with ‘debug’ enabled.
2025-04-10T16:03:48.207+08:00 ERROR 35784 — [wemedia-oss-nacos] [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘scopedTarget.nacosConfigClientController’: Injection of autowired dependencies failed
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:499) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean 1 ( A b s t r a c t B e a n F a c t o r y . j a v a : 364 ) [ s p r i n g ? b e a n s ? 6.1.1. j a r : 6.1.1 ] a t o r g . s p r i n g f r a m e w o r k . c l o u d . c o n t e x t . s c o p e . G e n e r i c S c o p e 1(AbstractBeanFactory.java:364) ~[spring-beans-6.1.1.jar:6.1.1] at org.springframework.cloud.context.scope.GenericScope 1(AbstractBeanFactory.java:364)?[spring?beans?6.1.1.jar:6.1.1]atorg.springframework.cloud.context.scope.GenericScopeBeanLifecycleWrapper.getBean(GenericScope.java:375) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:179) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:361) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1173) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.cloud.context.scope.refresh.RefreshScope.eagerlyInitialize(RefreshScope.java:126) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.context.scope.refresh.RefreshScope.start(RefreshScope.java:118) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.context.scope.refresh.RefreshScope.onApplicationEvent(RefreshScope.java:113) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.cloud.context.scope.refresh.RefreshScope.onApplicationEvent(RefreshScope.java:68) ~[spring-cloud-context-4.1.0.jar:4.1.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:149) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:445) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:968) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:619) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331) ~[spring-boot-3.2.0.jar:3.2.0]
at com.wemedia.NacosApplication.main(NacosApplication.java:11) ~[classes/:na]

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘config.info’ in value"${config.info}

at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-6.1.1.jar:6.1.1]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-6.1.1.jar:6.1.1]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-6.1.1.jar:6.1.1]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-6.1.1.jar:6.1.1]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:200) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:921) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1372) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1348) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:769) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:752) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.1.1.jar:6.1.1]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:493) ~[spring-beans-6.1.1.jar:6.1.1]
... 27 common frames omitted

2025-04-10T16:03:48.209+08:00 WARN 35784 — [wemedia-oss-nacos] [ Thread-1] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient
2025-04-10T16:03:48.209+08:00 WARN 35784 — [wemedia-oss-nacos] [ Thread-7] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Start destroying Publisher
2025-04-10T16:03:48.209+08:00 WARN 35784 — [wemedia-oss-nacos] [ Thread-7] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Destruction of the end
2025-04-10T16:03:48.210+08:00 WARN 35784 — [wemedia-oss-nacos] [ Thread-1] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Destruction of the end

Process finished with exit code 1

錯誤原因分析:
1.檢查關鍵代碼

server:port: 8877spring:application:name: wemedia-oss-nacosprofiles:active: dev#    active: test#    active: pred#    active: prodcloud:nacos:username: 'nacos'password: '123456'discovery:server-addr: 127.0.0.1:8848config:server-addr: 127.0.0.1:8848file-extension: properties  #必須指定nacos中dataid的后綴類型:yaml/properties在這里插入代碼片

@RestController
@RefreshScope // 支持動態刷新功能
public class NacosConfigClientController {@Value("${config.info}")private String configInfo;@GetMapping("/config/info")public String getConfigInfo() {return configInfo;}public void setConfigInfo(String configInfo) {this.configInfo = configInfo;}
}

配置文件出現問題,有幾種可能

  1. 配置文件格式寫錯
    配置文件的格式只能是這幾種:
    在這里插入圖片描述
    == 必須與你spring cloud中指定的file-extension的格式保持一致==

  2. 文件格式寫錯

  3. 沒有按照命名規范配置配置文件
    配置文件命名方式:

${spring.application.name}-${spring.profile.active}.${spring.cloud.nacos.config.file-extension}Data ID:wemedia-oss-nacos-dev.properties

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/76637.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/76637.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/76637.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

第三篇:Python數據結構深度解析與工程實踐

第一章:列表與字典 1.1 列表的工程級應用 1.1.1 動態數組實現機制 Python列表底層采用動態數組結構,初始分配8個元素空間,當空間不足時按0,4,8,16,25,35...的公式擴容,每次擴容增加約12.5%的容量 通過sys模塊可驗證擴容過程: import sys lst = [] prev_size = 0 for …

NOIP2015提高組.運輸計劃

目錄 題目算法標簽: 樹上倍增, l c a lca lca, 前綴和, 樹上差分, 二分思路代碼* v e c t o r vector vector存鄰接表會超時 題目 521. 運輸計劃 算法標簽: 樹上倍增, l c a lca lca, 前綴和, 樹上差分, 二分 思路 注意到答案是具有二分性質的, 對于某個時間 m i d mid …

MySQL數據過濾、轉換與標準化

數據處理是數據庫操作的重要組成部分,尤其是在大量數據中查找、轉換和規范化目標信息的過程中。為了確保數據的有效性與一致性,MySQL提供了一系列數據過濾、轉換與標準化的功能。 本教程將深入探討數據過濾和轉換的基本方法及應用,內容涵蓋數…

英語學習4.11

gear 【名詞 / 動詞】 👉 關鍵詞:齒輪、裝備、調節、使適應 名詞釋義: 齒輪: 一種機械裝置,用于傳遞動力或調節運動。 裝備、工具: 指用于某種活動的設備或工具。 汽車檔位: 汽車中用于改變…

SDC命令詳解:使用相對路徑訪問設計對象(current_instance命令)

相關閱讀 SDC命令詳解https://blog.csdn.net/weixin_45791458/category_12931432.html?spm1001.2014.3001.5482 在使用get_cells等命令訪問設計對象時,需要指定設計對象的名字,這個名字是一個相對路徑,本文就將對此進行討論。 相對路徑 使…

【問題記錄】記錄2個安裝Centos/Anolis系統卡死在安裝包階段的問題?(硬盤分區?換設備)

背景 問題就不詳細記錄了,本文記錄的是Centos/Anolis安裝中卡主的問題。這個問題遇到過幾十次了,嘗試過各種方法。最近一個偶然因素找到了原因。然后翻看歷史上出現這個問題的照片居然是相同的地方卡死。。。 有點意思。特此記錄,希望未來遇…

微信小程序中的openid的作用

微信小程序中的openid的作用 引言 在當今數字化時代,用戶體驗成為了產品成功與否的關鍵因素之一。微信小程序作為連接用戶與服務的重要橋梁,在提升用戶體驗方面發揮著重要作用。其中, openid(開放身份標識符)是微信小…

《Python星球日記》第25天:Pandas 數據分析

名人說:路漫漫其修遠兮,吾將上下而求索。—— 屈原《離騷》 創作者:Code_流蘇(CSDN)(一個喜歡古詩詞和編程的Coder😊) 訂閱專欄:《Python星球日記》 目錄 一、引言二、數據分組與聚合1. 分組操…

分布式系統-腦裂,redis的解決方案

感謝你的反饋!很高興能幫到你。關于你提到的“腦裂”(split-brain),這是一個分布式系統中的常見術語,尤其在像 Redis Cluster 這樣的高可用集群中會涉及。既然你問到了,我會從頭解釋“腦裂”的含義、Redis …

重構藝術 | 如何優雅地“提煉函數“

在工作中總數遇到非常多的長代碼,俗稱“屎山”,這類代碼讀起來特別費勁。自己想重構一遍,但是總感覺缺乏經驗指導,因此,多讀書,讀好書可能是最優解之一。讀《重構改善即有代碼的設計》有感,便寫…

每天學一個 Linux 命令(13):touch

Linux 文件管理命令:touch touch 是 Linux 中一個簡單但高頻使用的命令,主要用于創建空文件或修改文件的時間戳(訪問時間、修改時間)。它是文件管理和腳本操作的實用工具。 1. 命令作用 創建空文件:快速生成一個或多個空白文件。更新時間戳:修改文件的訪問時間(Access …

STM32HAL庫學習筆記

目錄 定時器 一些小細節 輸入捕獲計算信號頻率 輸入捕獲計算占空比與頻率 使用定時器不改變占空比的同時改變頻率的方法 串口 重定向原理 重定向代碼 怎么從串口接收到的字符串數據中解析出float型的數據 strchr sscanf memset 第一種實現方法 RTC實時時鐘 LCD顯…

Docker 鏡像、容器與數據卷的高效管理:最佳實踐與自動化腳本20250411

Docker 鏡像、容器與數據卷的高效管理:最佳實踐與自動化腳本 引言 在現代軟件開發中,容器化技術正變得越來越重要。Docker 作為容器化的代表工具,在各大企業中得到了廣泛的應用。然而,隨著容器化應用的增多,如何高效…

Selenium之Actions事件

鼠標、鍵盤組合鍵 在使用selenium的時候,有的時候我們需要鼠標單擊、雙擊、拖動;或者是按下鍵盤的某個鍵,松開某個按鍵,以及組合鍵的使用;今天我們就來看一看,怎么樣實現上面的操作 先把準備工作做好&…

如何在 CentOS 7 系統上以容器方式部署 GitLab,使用 ZeroNews 通過互聯網訪問 GitLab 私有倉庫,進行代碼版本發布與更新

第 1 步: 部署 GitLab 容器? 在開始部署 GitLab 容器之前,您需要創建本地目錄來存儲 GitLab 數據、配置和日志: #創建本地目錄 mkdir -p /opt/docker/gitlab/data mkdir -p /opt/docker/gitlab/config mkdir -p /opt/docker/gitlab/log#gi…

.py文件和.ipynb文件的區別:完整教程

一、概述 Python開發者常用的兩種文件格式.py和.ipynb各有特點,本教程將通過對比分析、代碼示例和場景說明,幫助開發者全面理解二者的區別與聯系。 二、核心區別對比 1. 文件格式本質 特性.ipynb文件.py文件文件類型JSON結構化文檔純文本文件存儲內容…

Go 字符串四種拼接方式的性能對比

簡介 使用完整的基準測試代碼文件,可以直接運行來比較四種字符串拼接方法的性能。 for 索引 的方式 for range 的方式 strings.Join 的方式 strings.Builder 的方式 寫一個基準測試文件 echo_bench_test.go package mainimport ("os""stri…

從代碼學習深度學習 - Bahdanau注意力 PyTorch版

文章目錄 1. 前言為什么選擇Bahdanau注意力本文目標與預備知識2. Bahdanau注意力機制概述注意力機制簡述加性注意力與乘性注意力對比Bahdanau注意力的數學原理與流程圖數學原理流程圖可視化與直觀理解3. 數據準備與預處理數據集簡介數據加載與預處理1. 讀取數據集2. 預處理文本…

19【動手學深度學習】卷積層

1. 從全連接到卷積 2. 圖像卷積 3. 圖形卷積代碼 互相關操作 import torch from torch import nn from d2l import torch as d2ldef corr2d(X, K):"""計算2維互相關運算"""h, w K.shapeY torch.zeros((X.shape[0]-h1, X.shape[1]-w 1))for …

Linux xorg-server 解析(一)- 編譯安裝Debug版本的xorg-server

一:下載代碼 1. 配置源,以Ubuntu24.04 為例( /etc/apt/sources.list.d/ubuntu.sources): 2. apt source xserver-xorg-core 二:編譯代碼 1. sudo apt build-dep ./ 2. DEB_BUILD_OPTIONS="nostrip" DEB_CFLAGS_SET="-g -O0" dpkg-buildpac…