SpringBoot的配置如何动态刷新(Nacos实现)

SpringBoot整合Nacos配置中心,实现动态刷新 SpringBoot整合nacos,并实现动态刷新 阅读详情

Nacos启动加载配置

        通过  META-INF/spring.factories 加载  NacosConfigBootstrapConfiguration

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration

初始化 NacosConfigProperties 和 NacosPropertySourceLocator

@Configuration
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
public class NacosConfigBootstrapConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public NacosConfigProperties nacosConfigProperties() {
		return new NacosConfigProperties();
	}

	@Bean
	public NacosPropertySourceLocator nacosPropertySourceLocator(
			NacosConfigProperties nacosConfigProperties) {
		return new NacosPropertySourceLocator(nacosConfigProperties);
	}

}

通过 com.alibaba.cloud.nacos.client.NacosPropertySourceLocator 加载配置到 org.springframework.core.env.Environment

@Override
	public PropertySource<?> locate(Environment env) {

		ConfigService configService = nacosConfigProperties.configServiceInstance();

		if (null == configService) {
			log.warn("no instance of config service found, can't load config from nacos");
			return null;
		}
		long timeout = nacosConfigProperties.getTimeout();
		nacosPropertySourceBuilder = new NacosPropertySourceBuilder(configService,
				timeout);
		String name = nacosConfigProperties.getName();

		String dataIdPrefix = nacosConfigProperties.getPrefix();
		if (StringUtils.isEmpty(dataIdPrefix)) {
			dataIdPrefix = name;
		}

		if (StringUtils.isEmpty(dataIdPrefix)) {
			dataIdPrefix = env.getProperty("spring.application.name");
		}

		CompositePropertySource composite = new CompositePropertySource(
				NACOS_PROPERTY_SOURCE_NAME);

		loadSharedConfiguration(composite);
		loadExtConfiguration(composite);
		loadApplicationConfiguration(composite, dataIdPrefix, nacosConfigProperties, env);

		return composite;
	}

Nacos启动注册 com.alibaba.nacos.api.config.listener.Listener

通过  META-INF/spring.factories 加载  NacosConfigAutoConfiguration

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alibaba.cloud.nacos.NacosConfigAutoConfiguration,\
com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration

初始化 com.alibaba.cloud.nacos.refresh.NacosContextRefresher 实现启动注册 Listener

    @Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		// many Spring context
		if (this.ready.compareAndSet(false, true)) {
			this.registerNacosListenersForApplications();
		}
	}

    private void registerNacosListenersForApplications() {
		if (refreshProperties.isEnabled()) {
			for (NacosPropertySource nacosPropertySource : NacosPropertySourceRepository
					.getAll()) {

				if (!nacosPropertySource.isRefreshable()) {
					continue;
				}

				String dataId = nacosPropertySource.getDataId();
				registerNacosListener(nacosPropertySource.getGroup(), dataId);
			}
		}
	}

	private void registerNacosListener(final String group, final String dataId) {

		Listener listener = listenerMap.computeIfAbsent(dataId, i -> new Listener() {
			@Override
			public void receiveConfigInfo(String configInfo) {
				refreshCountIncrement();
				String md5 = "";
				if (!StringUtils.isEmpty(configInfo)) {
					try {
						MessageDigest md = MessageDigest.getInstance("MD5");
						md5 = new BigInteger(1, md.digest(configInfo.getBytes("UTF-8")))
								.toString(16);
					}
					catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
						log.warn("[Nacos] unable to get md5 for dataId: " + dataId, e);
					}
				}
				refreshHistory.add(dataId, md5);
				applicationContext.publishEvent(
						new RefreshEvent(this, null, "Refresh Nacos config"));
				if (log.isDebugEnabled()) {
					log.debug("Refresh Nacos config group " + group + ",dataId" + dataId);
				}
			}

			@Override
			public Executor getExecutor() {
				return null;
			}
		});

		try {
			configService.addListener(dataId, group, listener);
		}
		catch (NacosException e) {
			e.printStackTrace();
		}
	}

 通过 applicationContext.publishEvent(new RefreshEvent(this, null, "Refresh Nacos config")); 发布更新事件, 触发监听器操作 org.springframework.cloud.endpoint.event.RefreshEventListener

org.springframework.cloud.endpoint.event.RefreshEventListener


    @Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return ApplicationReadyEvent.class.isAssignableFrom(eventType)
				|| RefreshEvent.class.isAssignableFrom(eventType);
	}

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof ApplicationReadyEvent) {
			handle((ApplicationReadyEvent) event);
		}
		else if (event instanceof RefreshEvent) {
			handle((RefreshEvent) event);
		}
	}

	public void handle(ApplicationReadyEvent event) {
		this.ready.compareAndSet(false, true);
	}

	public void handle(RefreshEvent event) {
		if (this.ready.get()) { // don't handle events before app is ready
			log.debug("Event received " + event.getEventDesc());
			Set<String> keys = this.refresh.refresh();
			log.info("Refresh keys changed: " + keys);
		}
	}

监听器触发调用 org.springframework.cloud.context.refresh.ContextRefresher.refresh()

	public synchronized Set<String> refresh() {
		Set<String> keys = refreshEnvironment();
		this.scope.refreshAll();
		return keys;
	}

	public synchronized Set<String> refreshEnvironment() {
		Map<String, Object> before = extract(
				this.context.getEnvironment().getPropertySources());
		addConfigFilesToEnvironment();
		Set<String> keys = changes(before,
				extract(this.context.getEnvironment().getPropertySources())).keySet();
		this.context.publishEvent(new EnvironmentChangeEvent(this.context, keys));
		return keys;
	}



Set<String> keys = refreshEnvironment();
    1. 实现 Environment 的刷新 
    2. 获取配置发生变化的 key
    3. EnvironmentChangeEvent 事件的发布, 触发监听 
org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder
实现 org.springframework.boot.context.properties.ConfigurationProperties 注解的刷新


this.scope.refreshAll();
    刷新 org.springframework.cloud.context.scope.refresh.RefreshScope 管理的Bean


Nacos实现监听

通过  META-INF/spring.factories 加载  NacosConfigAutoConfiguration

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alibaba.cloud.nacos.NacosConfigAutoConfiguration,\
com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration

根据配置获取 com.alibaba.nacos.api.config.ConfigService

设置  com.alibaba.nacos.client.config.impl.ClientWorker

 1. 获取ConfigService  com.alibaba.cloud.nacos.NacosConfigAutoConfiguration.nacosContextRefresher(NacosConfigProperties, NacosRefreshProperties, NacosRefreshHistory)

     @Bean
	public NacosContextRefresher nacosContextRefresher(
			NacosConfigProperties nacosConfigProperties,
			NacosRefreshProperties nacosRefreshProperties,
			NacosRefreshHistory refreshHistory) {
		return new NacosContextRefresher(nacosRefreshProperties, refreshHistory,
				nacosConfigProperties.configServiceInstance());
	}

2. 获取 ConfigService  
com.alibaba.cloud.nacos.NacosConfigProperties.configServiceInstance()

3. 工厂方法获取 ConfigService
com.alibaba.nacos.api.NacosFactory.createConfigService(Properties)

    public static ConfigService createConfigService(Properties properties) throws NacosException {
        try {
            Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.config.NacosConfigService");
            Constructor constructor = driverImplClass.getConstructor(Properties.class);
            ConfigService vendorImpl = (ConfigService) constructor.newInstance(properties);
            return vendorImpl;
        } catch (Throwable e) {
            throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
        }
    }

4. 反射生成 NacosConfigService
com.alibaba.nacos.client.config.NacosConfigService.NacosConfigService(Properties)

    public NacosConfigService(Properties properties) throws NacosException {
        String encodeTmp = properties.getProperty(PropertyKeyConst.ENCODE);
        if (StringUtils.isBlank(encodeTmp)) {
            encode = Constants.ENCODE;
        } else {
            encode = encodeTmp.trim();
        }
        initNamespace(properties);
        agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
        agent.start();
        worker = new ClientWorker(agent, configFilterChainManager, properties);
    }

5. 实例化 ClientWorker
com.alibaba.nacos.client.config.impl.ClientWorker.ClientWorker(HttpAgent, ConfigFilterChainManager, Properties)

ClientWorker 实现定时检测 10ms 检测一次

@SuppressWarnings("PMD.ThreadPoolCreationRule")
    public ClientWorker(final HttpAgent agent, final ConfigFilterChainManager configFilterChainManager, final Properties properties) {
        this.agent = agent;
        this.configFilterChainManager = configFilterChainManager;

        // Initialize the timeout parameter

        init(properties);

        executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName("com.alibaba.nacos.client.Worker." + agent.getName());
                t.setDaemon(true);
                return t;
            }
        });

        executorService = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName("com.alibaba.nacos.client.Worker.longPolling." + agent.getName());
                t.setDaemon(true);
                return t;
            }
        });

        executor.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                try {
                    checkConfigInfo();
                } catch (Throwable e) {
                    LOGGER.error("[" + agent.getName() + "] [sub-check] rotate check error", e);
                }
            }
        }, 1L, 10L, TimeUnit.MILLISECONDS);
    }



executor 定时运行 com.alibaba.nacos.client.config.impl.ClientWorker.checkConfigInfo()
    单线程 10ms 执行一次
executorService 运行 LongPollingRunnable 

LongPollingRunnable 长轮训实现变化通知

com.alibaba.nacos.client.config.impl.ClientWorker.LongPollingRunnable


        @Override
        public void run() {

            List<CacheData> cacheDatas = new ArrayList<CacheData>();
            List<String> inInitializingCacheList = new ArrayList<String>();
            try {
                // check failover config
                for (CacheData cacheData : cacheMap.get().values()) {
                    if (cacheData.getTaskId() == taskId) {
                        cacheDatas.add(cacheData);
                        try {
                            checkLocalConfig(cacheData);
                            if (cacheData.isUseLocalConfigInfo()) {
                                cacheData.checkListenerMd5();
                            }
                        } catch (Exception e) {
                            LOGGER.error("get local config info error", e);
                        }
                    }
                }

                // check server config
                List<String> changedGroupKeys = checkUpdateDataIds(cacheDatas, inInitializingCacheList);

                for (String groupKey : changedGroupKeys) {
                    String[] key = GroupKey.parseKey(groupKey);
                    String dataId = key[0];
                    String group = key[1];
                    String tenant = null;
                    if (key.length == 3) {
                        tenant = key[2];
                    }
                    try {
                        String content = getServerConfig(dataId, group, tenant, 3000L);
                        CacheData cache = cacheMap.get().get(GroupKey.getKeyTenant(dataId, group, tenant));
                        cache.setContent(content);
                        LOGGER.info("[{}] [data-received] dataId={}, group={}, tenant={}, md5={}, content={}",
                            agent.getName(), dataId, group, tenant, cache.getMd5(),
                            ContentUtils.truncateContent(content));
                    } catch (NacosException ioe) {
                        String message = String.format(
                            "[%s] [get-update] get changed config exception. dataId=%s, group=%s, tenant=%s",
                            agent.getName(), dataId, group, tenant);
                        LOGGER.error(message, ioe);
                    }
                }
                for (CacheData cacheData : cacheDatas) {
                    if (!cacheData.isInitializing() || inInitializingCacheList
                        .contains(GroupKey.getKeyTenant(cacheData.dataId, cacheData.group, cacheData.tenant))) {
                        cacheData.checkListenerMd5();
                        cacheData.setInitializing(false);
                    }
                }
                inInitializingCacheList.clear();

                executorService.execute(this);

            } catch (Throwable e) {

                // If the rotation training task is abnormal, the next execution time of the task will be punished
                LOGGER.error("longPolling error : ", e);
                executorService.schedule(this, taskPenaltyTime, TimeUnit.MILLISECONDS);
            }
        }
    }
## com.alibaba.nacos.client.config.impl.ClientWorker.LongPollingRunnable

1. 循环遍历 CacheData
2. 检测本地配置
    com.alibaba.nacos.client.config.impl.ClientWorker.checkLocalConfig(CacheData)
3. 如果是 本地配置,执行md5对比
    if (cacheData.isUseLocalConfigInfo()) { cacheData.checkListenerMd5(); }


## com.alibaba.nacos.client.config.impl.CacheData
1. 执行 md5 对比
    com.alibaba.nacos.client.config.impl.CacheData.checkListenerMd5()
2. 如果 md5 发生变化, 执行回调
    com.alibaba.nacos.client.config.impl.CacheData.safeNotifyListener(String, String, String, String, ManagerListenerWrap)
3. 执行 listener 回调 : 存在线程池, 线程池执行, 不存在直接运行




private void safeNotifyListener(final String dataId, final String group, final String content,
                                    final String md5, final ManagerListenerWrap listenerWrap) {
        final Listener listener = listenerWrap.listener;

        Runnable job = new Runnable() {
            @Override
            public void run() {
                ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader();
                ClassLoader appClassLoader = listener.getClass().getClassLoader();
                try {
                    if (listener instanceof AbstractSharedListener) {
                        AbstractSharedListener adapter = (AbstractSharedListener) listener;
                        adapter.fillContext(dataId, group);
                        LOGGER.info("[{}] [notify-context] dataId={}, group={}, md5={}", name, dataId, group, md5);
                    }
                    // 执行回调之前先将线程classloader设置为具体webapp的classloader,以免回调方法中调用spi接口是出现异常或错用(多应用部署才会有该问题)。
                    Thread.currentThread().setContextClassLoader(appClassLoader);

                    ConfigResponse cr = new ConfigResponse();
                    cr.setDataId(dataId);
                    cr.setGroup(group);
                    cr.setContent(content);
                    configFilterChainManager.doFilter(null, cr);
                    String contentTmp = cr.getContent();
                    listener.receiveConfigInfo(contentTmp);
                    listenerWrap.lastCallMd5 = md5;
                    LOGGER.info("[{}] [notify-ok] dataId={}, group={}, md5={}, listener={} ", name, dataId, group, md5,
                        listener);
                } catch (NacosException de) {
                    LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} errCode={} errMsg={}", name,
                        dataId, group, md5, listener, de.getErrCode(), de.getErrMsg());
                } catch (Throwable t) {
                    LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} tx={}", name, dataId, group,
                        md5, listener, t.getCause());
                } finally {
                    Thread.currentThread().setContextClassLoader(myClassLoader);
                }
            }
        };

        final long startNotify = System.currentTimeMillis();
        try {
            if (null != listener.getExecutor()) {
                listener.getExecutor().execute(job);
            } else {
                job.run();
            }
        } catch (Throwable t) {
            LOGGER.error("[{}] [notify-error] dataId={}, group={}, md5={}, listener={} throwable={}", name, dataId, group,
                md5, listener, t.getCause());
        }
        final long finishNotify = System.currentTimeMillis();
        LOGGER.info("[{}] [notify-listener] time cost={}ms in ClientWorker, dataId={}, group={}, md5={}, listener={} ",
            name, (finishNotify - startNotify), dataId, group, md5, listener);
    }

com.alibaba.nacos.api.config.listener.Listener 触发 receiveConfigInfo 即可发布刷新事件,完成RefreshEvent 的触发

Spring Cloud Alibaba Nacos Config - - - >@RefreshScope动态获取刷新后的配置内容 配置通常用在 Bean 里面,在 Bean 中通过@Value 注解来获取配置信息,但 @Value 可以获取到配置中心的值,却无法动态感知获取修改后的配置内容。想要 @Value 可以动态获取配置修改后的值,需要在 Bean 上添加 @RefreshScope 注解。 阅读详情

相关推荐

SpringBoot集成Nacos配置中心:从基础配置到动态刷新实战

本文详细介绍了SpringBoot集成Nacos配置中心的完整流程,从基础环境配置到动态刷新机制实现。通过核心注解使用、多环境管理、安全配置等实战案例,帮助开发者快速掌握Nacos在微服务架构中的配置管理能力,提升应用的可维护性和灵活性。

weixin_30902251的博客 530

实现Nacos属性值自动刷新的三种方式

在Spring Boot项目中,我们经常使用Nacos作为配置中心,用于管理应用程序的属性配置。当我们在Nacos上修改属性值时,希望应用程序能够自动刷新并应用最新的属性值,以避免重启应用。本篇博客将介绍三种实现Nacos属性值自动刷新的方式,并提供相应的示例代码。

算命de博客 8502

SpringBoot应用如何借助Nacos实现配置的集中管理与动态刷新

本文详细介绍了SpringBoot应用如何通过Nacos实现配置的集中管理与动态刷新。从环境搭建到生产部署,涵盖了命名空间规划、配置文件最佳实践、动态刷新机制及常见问题排查,帮助开发者高效管理微服务配置,提升运维效率。

weixin_26869081的博客 388

如何实现Nacos配置文件动态刷新【四种方式】

在Nacos中,动态刷新配置文件的实现方式可以总结如下:使用Spring Cloud Config + Nacos:结合Spring Cloud Config和Nacos作为配置中心,在应用程序中添加注解,并使用@Value注解绑定配置属性。通过发送POST请求到端点来触发配置的刷新。使用Nacos的ConfigListener接口:实现ConfigListener接口,并注册为Nacos的监听器。当配置发生变化时,回调相应方法进行处理。

怀着一颗学徒的心 2万+

【spring boot】[nacos] ----一篇文章搞懂 nacos 底层动态刷新配置原理超详细

Nacos实现动态配置刷新的核心在于长轮询机制和应用内配置更新。客户端每30秒发起一次长轮询请求,服务端有变更立即返回数据,无变更则阻塞30秒后响应。获取新配置后,客户端会重新加载完整的配置文件,并触发@RefreshScope标记的Bean重新初始化。这种机制适用于可热更新的无状态配置,如开关参数、业务规则等,但对于数据库连接等关键配置需谨慎处理,避免运行时错误。通过将配置管理从本地静态加载转为远程动态监听,实现了配置变更的实时生效而无需重启服务。

记录生活 1225

SpringBoot+Nacos配置安全升级:Jasypt 3.0.5实现敏感信息加密与动态刷新

在微服务架构中,配置中心集中管理着数据库密码、API密钥等敏感信息,其安全性至关重要。配置加密是保障数据安全的基础技术,其核心原理是在存储和传输过程中对敏感数据进行混淆处理,防止明文泄露。Jasypt作为Java生态中成熟的加密库,提供了非侵入式的透明解密方案,能无缝集成Spring框架,在属性加载阶段自动识别并解密密文,对业务代码零侵入。其技术价值在于,它实现了“配置中心存密文,应用内存用明文”的安全状态,有效防范因配置泄露导致的数据拖库、密钥盗用等安全风险。该方案尤其适用于使用Nacos、Apollo等

weixin_34378767的博客 334

nacos 配置动态刷新_springboot2.x整合nacos配置服务实现配置获取及刷新

本文我将带领大家在springboot2.x的开发框架中整合alibaba-nacos,实现配置获取及刷新等功能。引用官方介绍:Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,帮助您实现动态服务发现、服务配置管理、服务及流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。Nacos 是构建以“服务”为中心的现代应用架构(例如微服务范式、云原...

weixin_36192634的博客 1117

Springboot 接口方式硬通知实现ConfigurationProperties 、@Value 动态刷新

Springboot 接口方式硬通知实现 动态刷新配置值,@ConfigurationProperties 、@Value 都可以

默默不代表沉默 1914

nacos+springboot配置文件动态刷新源码实现分析

nacos+spring配置自动刷新原理

Tt1814964226的博客 1007

Hive中的四种排序方式(order by,sort by,distribute by,cluster by)使用与区别详解

在平时的Hive数仓开发工作中经常会用到排序,而Hive中支持的排序方式有四种,这里结合具体的案例详细介绍一下他们的使用与区别: order by sort by distribute by cluster by 一、order by(全局排序) 1、作用:全局排序,只有一个reducer。 order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序),也正因为只有一个reducer,所以当输入的数据规模较大时会导致计算时间较长。   set hive.mapr

weixin_43230682的博客 1万+

电磁兼容标准体系解析:从基础到认证的完整指南

本文系统解析了电磁兼容(EMC)标准体系,从基础概念到认证流程提供完整指南。文章阐述了EMC对于产品可靠性与市场准入的重要性,详细拆解了基础标准、通用标准、产品类标准及认证流程四层结构,并结合5G设备与工业控制等实战案例,为工程师提供了从设计初期到认证测试的高效应用策略。

weixin_29294975的博客 361

nacos 配置不会动态刷新_springboot nacos使用配置

前言随着框架的不断更新迭代,springboot、springcloud使用率越来越高,注册中心、动态配置等成为日常开发中一项重要的存在,nacos这款外部应用,侵入性小的组件也越来被开发者所接受,今天小编来盘盘它☺1.nacos传送门【目前最新版本1.3.2】https://github.com/alibaba/nacos/releases2.将下载好的nacos1.3.2解压,并将MySQL依...

weixin_39775428的博客 1210

【ComfyUI报错解决】K采样器 mat1和mat2形状不匹配错误分析与修复 mat1 and mat2 shapes cannot be multiplied (77x2048 and 4096x

如果你在 ComfyUI 里遇到K采样器报错:mat1 和 mat2 shapes cannot be multiplied确认大模型和 LoRA 是否是同一版本(SDXL vs SD1.5,不能混用)。如果用了双 CLIP 加载器,要确认加载的类型和选择的模型类型是否匹配。加载→ 类型选flux加载 SDXL 专用的 clip/t5 → 类型选sdxl避免不同版本模型和 LoRA 混搭,保持一致性。模型+LoRA+CLIP 类型必须保持同一版本,不然就会报错。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 2420

nacos动态配置数据源_SpringBoot集成nacos动态刷新数据源的实现示例

前言因为项目需要,需要在项目运行过程中能够动态修改数据源(即:数据源的热更新)。这里以com.alibaba.druid.pool.DruidDataSource数据源为例第一步:重写DruidAbstractDataSource类这里为什么要重写这个类:因为DruidDataSource数据源在初始化后,就不允许再重新设置数据库的url和userNamepublic void setUrl(St...

weixin_32187075的博客 1082

高云FPGA系列教程(1):FPGA和ARM开发环境搭建

至此,高云FPGA和MCU开发环境就搭建完成了,整体还是比较简单的,几乎是一键完成,下一篇文章我们进行实际的FPGA和MCU开发。本文是高云FPGA系列教程的第1篇文章。

whik1194的博客 6206

手把手教你学simulink(42.1)--储能系统场景示例:基于Simulink的电池+超级电容器混合储能系统

混合储能系统(HESS)结合了电池和超级电容器的优点,能够在满足高功率需求的同时提供较长的持续放电时间。这种组合特别适合用于电动汽车、可再生能源发电系统、电网频率调节等应用场景。本项目将详细介绍如何在MATLAB/Simulink中搭建一个完整的基于电池和超级电容器的混合储能系统,并提供具体的代码实现和设计步骤。如果你需要实现更复杂的控制逻辑,可以使用MATLAB Function模块。以下是一个简单的例子,展示了如何在该模块中实现一个条件逻辑,以分配电池和超级电容器的充放电任务。Matlab。

MHD0815的博客 548

nacos 配置动态刷新_springboot nacos使用配置

前言随着框架的不断更新迭代,springboot、springcloud使用率越来越高,注册中心、动态配置等成为日常开发中一项重要的存在,nacos这款外部应用,侵入性小的组件也越来被开发者所接受,今天小编来盘盘它☺1.nacos传送门【目前最新版本1.3.2】https://github.com/alibaba/nacos/releases2.将下载好的nacos1.3.2解压,并将MySQL依...

weixin_34512840的博客 1140

路由三大分类:直连路由、静态路由、动态路由

直连路由、静态路由和动态路由各有其独特的特点和适用场景。直连路由适用于简单的直接连接网络,静态路由提供了精确的路径控制,而动态路由则在大型复杂网络中展现出强大的适应性和自动化能力。了解和掌握这三种路由类型的配置和管理,对于网络管理员来说,是确保网络高效、安全运行的重要技能。

网络技术联盟站 4725

SpringBoot整合nacos配置中心 支持动态刷新

自己搜了好多相关的文章发现好多都是springcloud的居多 关于springboot的很少 如果你也跟我一样不是微服务的项目话那么或许会帮到你。这里我们不能新建bootstrap.yml来进行配置 我们得使用原始的配置文件进行配置就可以了。到此关于nacos服务端的配置完毕 以上跟微服务的操作基本一致 所以在此就不贴图详细赘述了。在命名空间内新建一个新的命名空间 方便后期的维护 避免和其他项目混在一起。3.在配置列表内选择自己的命名空间建立新的配置。auto-refresh改为 true。

weixin_48692011的博客 1598

基于 YOLOv8 的自动驾驶车辆障碍物检测与避障路径规划

本文探讨基于YOLOv8的自动驾驶车辆障碍物检测与避障路径规划系统。在感知层面,采用YOLOv8模型实现多类别障碍物识别,结合单目视觉距离估计和ByteTrack多目标跟踪算法,完成障碍物的稳定检测与运动状态估计。在路径规划层面,设计分层规划架构,融合全局路径规划与局部避障算法,重点实现Frenet坐标系下的采样优化算法和基于模型预测控制的实时避障轨迹生成。通过完整的代码实现与仿真实验,验证系统在复杂交通场景下的有效性与实时性,为自动驾驶开发者提供从理论到实践的完整技术参考。 关键词:YOLOv8;自动驾驶

huanghm88的专栏 259

道路缺陷检测实战指南:基于YOLOv11的深度学习系统从搭建到落地

道路缺陷检测项目的每一步,都是“理论→实践→反思→优化”的成长循环。当你看到自己开发的系统能精准识别出道路上的每一处裂缝、每一个坑洼时,那种“技术解决真实问题”的成就感,会让你明白深度学习不止是论文里的公式,更是改变行业的工具。如果过程中遇到模型不收敛、界面功能异常等问题,不妨把问题拆解成“数据是否标注准确?”“模型参数是否合理?”“界面逻辑是否有漏洞?”等小问题逐一排查。记住,每解决一个问题,你就离“能独立落地AI项目的工程师”更近一步。

LXY_LOVE36的博客 175

nacos动态配置数据源_SpringBoot集成nacos动态刷新数据源实现代码示例

本篇文章小编给大家分享一下SpringBoot集成nacos动态刷新数据源实现代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。第一步:重写DruidAbstractDataSource类这里为什么要重写这个类:因为DruidDataSource数据源在初始化后,就不允许再重新设置数据库的url和userNamepublic void setU...

weixin_35691526的博客 2578

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

spring boot nacos 配置动态刷新

使用注解 @RefreshScope 来达到配置动态刷新的效果,也可以加载 controller 上使配置动态刷新,本次使用配置类。共享配置使用动态刷新需要开启动态刷新配置。

zhucegemingzizheng的博客 2380

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

nacos 配置动态刷新_spring boot 配置文件动态更新原理 以Nacos为例

配置文件的动态更新通常获取配置文件的方式1, @Value2. @ConfigurationProperties(Prefix)如果是在运行时要动态更新的话,第一种方式要在bean上加@RefreshScope第二种方式是自动支持的。以Nacos为为例,我们可以看下源码是如何实现的:Nacos获取配置中心是通过单独一个线程的长轮询获取的:com.alibaba.nacos.client.confi...

weixin_28822657的博客 2506

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

上一篇: SpringBoot的配置如何动态刷新(方案)
下一篇: SpringBoot的配置如何动态刷新(自定义)
xinyuan_java
博客等级 码龄12年 181粉丝 83原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值