构建修改

This commit is contained in:
XinWei 2024-08-28 09:45:37 +08:00
parent 5adf95ffd0
commit 514a14df8c

View File

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