本文整理汇总了Java中org.springframework.cloud.commons.util.InetUtils.HostInfo类的典型用法代码示例。如果您正苦于以下问题:Java HostInfo类的具体用法?Java HostInfo怎么用?Java HostInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HostInfo类属于org.springframework.cloud.commons.util.InetUtils包,在下文中一共展示了HostInfo类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postProcessEnvironment
import org.springframework.cloud.commons.util.InetUtils.HostInfo; //导入依赖的package包/类
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("spring.cloud.client.hostname", hostInfo.getHostname());
map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
MapPropertySource propertySource = new MapPropertySource(
"springCloudClientHostInfo", map);
environment.getPropertySources().addLast(propertySource);
}
示例2: getFirstNonLoopbackHostInfo
import org.springframework.cloud.commons.util.InetUtils.HostInfo; //导入依赖的package包/类
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
InetUtilsProperties target = new InetUtilsProperties();
ConfigurationPropertySources.attach(environment);
Binder.get(environment).bind(InetUtilsProperties.PREFIX,
Bindable.ofInstance(target));
try (InetUtils utils = new InetUtils(target)) {
return utils.findFirstNonLoopbackHostInfo();
}
}
示例3: testHostInfo
import org.springframework.cloud.commons.util.InetUtils.HostInfo; //导入依赖的package包/类
@Test
public void testHostInfo() throws Exception {
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
HostInfo info = utils.findFirstNonLoopbackHostInfo();
assertNotNull(info.getIpAddressAsInt());
}
}
示例4: getHostInfo
import org.springframework.cloud.commons.util.InetUtils.HostInfo; //导入依赖的package包/类
private HostInfo getHostInfo() {
return hostInfo;
}
示例5: setHostInfo
import org.springframework.cloud.commons.util.InetUtils.HostInfo; //导入依赖的package包/类
private void setHostInfo(HostInfo hostInfo) {
this.hostInfo = hostInfo;
}