diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java index dd9f3569f..5b4c0fae6 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.datacenter.framework.nacos.config; import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -13,15 +14,19 @@ public class BeanInit { /** * 用于改变程序自动获取的本机ip */ + @Value("${spring.profiles.active}") + private String activeEnv; @Bean @Primary public NacosDiscoveryProperties nacosProperties() throws UnknownHostException { NacosDiscoveryProperties nacosDiscoveryProperties = new NacosDiscoveryProperties(); - // 直接指定域名 - String customIp = "120.46.37.243"; // 替换为你的域名 - int customPort = 9091; // 替换为你的端口 - nacosDiscoveryProperties.setIp(customIp ); - nacosDiscoveryProperties.setPort(customPort); + if ("dev".equals(activeEnv)){ + // 直接指定域名 + String customIp = "120.46.37.243"; // 替换为你的域名 + int customPort = 9091; // 替换为你的端口 + nacosDiscoveryProperties.setIp(customIp); + nacosDiscoveryProperties.setPort(customPort); + } return nacosDiscoveryProperties; } }