Open Aloren opened 8 years ago
@Aloren are you using config server? if so it may need to go in bootstrap.properties.
@spencergibb No, I'm not using config server. How is it related to it? Code in HostInfoEnvironmentPostProcessor
uses static method from InetUtils:
public static HostInfo getFirstNonLoopbackHostInfo() {
return instance.findFirstNonLoopbackHostInfo();
}
Instance is initialized the following way:
private static final InetUtils instance = new InetUtils(new InetUtilsProperties());
This way InetUtilsProperties will not see any set up ignoredInterfaces
.
I want to get rid of that static method. But application.properties
is always going to be too late to influence the behaviour of the host info post processor. The whole point is that it sets up reasonable defaults for stuff that you then want to configure using placeholders in application.properties
.
Can't we use bootstrap.properties
? As I know it is initialised earlier than application.properties
.
See ff59dc8 for the deprecation. With that change you might be able to set ignoredInterfaces
in bootstrap.properties
(or via system properties).
Thank you! That is exactly what I needed!
I have the same problem (version 2.0.0.M4). My bootstrap.yml:
spring:
cloud:
inetutils:
preferred-networks:
- 10.0.
ignored-interfaces:
- lo
But in HostInfoEnvironmentPostProcessor my configure ignored and i can not using @Value("${spring.cloud.client.ip-address}") (because ip not correct).
I have to use:
@Autowired
private InetUtils inetUtils;
...
String address = inetUtils.findFirstNonLoopbackAddress().getHostAddress();
I have added the following property to my application.properties:
Enpoint /env shows following:
Ip address 222.222.222.222 is loopback interface. ifconfig of the machine:
I suppose this is not correct behaviour for springCloudClientHostInfo. I debugged HostInfoEnvironmentPostProcessor where the properties
spring.cloud.client.hostname
andspring.cloud.client.ipAddress
are added to environment -- at this stage InetUtilsProperties ignored interfaces variable is empty (looks like it was not yet postprocessed). Is there a quick fix for the issue?