两种方式实现
加入配置pom
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
1.实现Listener接口
package com.homepage.data.display.common.configbean;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.homepage.data.display.common.thread.pool.DashBoardThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.Executor;
@Configuration
public class SimpleNacosConfigListener implements InitializingBean {
private static final Logger logger = LoggerFactory
.getLogger(SimpleNacosConfigListener.class);
@Value("${spring.application.name}")
private String appName;
@Autowired
private DisplayAreaConfig displayAreaConfig;
@Autowired
private NacosConfigProperties configProperties;
@Autowire