Use IP registration in spring eurake

When developing spring cloud, I encountered a very strange problem, that is, when the service registers an instance with spring eureka, it uses the machine name, and then localhost, xxx.xx, etc. appear, as shown in the following figure:

eureka.instance.perferIpAddress=true

I don't know what spring cloud version this friend is using. Anyway, the spring cloud () version I use does not have this, but there are the following configurations,


​It is good to be able to

I also found some ideas on the Internet, such as this http://blog.csdn.net/cnhome/article/details/52291505, said configuration

eureka.instance.prefer-ip-address=true

The spring cloud maven dependencies I use are as follows:

<dependencies>

 <dependency>

 <groupId>org.springframework.cloud</groupId>

 <artifactId>spring-cloud-dependencies</artifactId>

 <version>Camden.RELEASE</version>

 <type>pom</type>

 <scope>import</scope>

 </dependency>

</dependencies>

Quickly add the configuration, and then send the package for testing, as shown in the figure below:

The display result is still the same, it is still the machine name, but if you look at the lower left corner, the URL connection address of the mouse has indeed changed to the IP, but the URL display is still the machine name, ok, at least part of it is solved, and the rest is the display problem.

Searching on the Internet, most of them say increase

eureka.instance.prefer-ip-address=true

​Configuration
, such as http://www.cnblogs.com/yish/p/5985074.html, http://blog.csdn.net/zhuchuangang/article/details/51202307, etc. did not solve the problem.

Finally, find the configuration at http://www.cnphp6.com/detail/17565, which needs to be configured

eureka.instance.preferIpAddress=true

eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}

ok, quickly upload the code and run the test, as shown in the figure below

ok, success, this is the result I hoped for.

Guess you like

Origin blog.csdn.net/m0_65038841/article/details/130004758