springboot将請求的ip保存?@Value("${server.port}")
private String port ;
,接下來我們就來聊聊關于springboot将請求的ip保存?以下内容大家不妨參考一二希望能幫到您!
@Value("${server.port}")
private String port ;
或者
@LocalServerPort
private String port ;
@Autowired
Environment environment;
public String getPort(){
return environment.getProperty("server.port");
}
public String getLocalIp(){
InetAddress localHost = null;
try {
localHost = Inet4Address.getLocalHost();
} catch (UnknownHostException e) {
logger.error(e.getMessage(),e);
}
String ip = localHost.getHostAddress();
return ip;
}
application.properties配置
url.mapping.outnet.ip=xx.xx.xx.xx
代碼獲取類似端口的獲取方式
@Autowired
Environment environment;
public String getPort(){
return environment.getProperty("local.server.port");
}
這個例子隻是思想,大家可以舉一反三。
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!