|
@ -2,11 +2,13 @@ package com.epmet.lbtest.controller; |
|
|
|
|
|
|
|
|
import com.epmet.lbtest.feign.TestCallFeignClient; |
|
|
import com.epmet.lbtest.feign.TestCallFeignClient; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.cloud.commons.util.InetUtils; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
import java.net.Inet4Address; |
|
|
import java.net.InetAddress; |
|
|
import java.net.InetAddress; |
|
|
import java.net.UnknownHostException; |
|
|
import java.net.UnknownHostException; |
|
|
|
|
|
|
|
@ -14,17 +16,14 @@ import java.net.UnknownHostException; |
|
|
@RequestMapping("lb") |
|
|
@RequestMapping("lb") |
|
|
public class LbController { |
|
|
public class LbController { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private InetUtils inetUtils; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private TestCallFeignClient testCallFeignClient; |
|
|
private TestCallFeignClient testCallFeignClient; |
|
|
|
|
|
|
|
|
@GetMapping("test") |
|
|
@GetMapping("test") |
|
|
public String test() { |
|
|
public String test() { |
|
|
String localAddr = null; |
|
|
return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|
|
try { |
|
|
|
|
|
localAddr = InetAddress.getLocalHost().getHostAddress(); |
|
|
|
|
|
} catch (UnknownHostException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
return localAddr; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|