本文整理匯總了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;
}