mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
refactor: close https://github.com/mybatis-flex/mybatis-flex/issues/470
This commit is contained in:
parent
de8f3865c4
commit
a96bb4af03
@ -23,14 +23,24 @@ import com.mybatisflex.core.audit.http.HttpUtil;
|
||||
*/
|
||||
public class DefaultMessageFactory implements MessageFactory {
|
||||
|
||||
private final String hostIp = HttpUtil.getHostIp();
|
||||
private String hostIp;
|
||||
|
||||
@Override
|
||||
public AuditMessage create() {
|
||||
AuditMessage message = new AuditMessage();
|
||||
message.setPlatform(FlexConsts.NAME);
|
||||
message.setHostIp(hostIp);
|
||||
message.setHostIp(getHostIp());
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getHostIp() {
|
||||
if (hostIp == null) {
|
||||
hostIp = HttpUtil.getHostIp();
|
||||
}
|
||||
return hostIp;
|
||||
}
|
||||
|
||||
public void setHostIp(String hostIp) {
|
||||
this.hostIp = hostIp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ public class HttpUtil {
|
||||
if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
|
||||
continue;
|
||||
}
|
||||
for (Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); addrs.hasMoreElements(); ) {
|
||||
InetAddress addr = addrs.nextElement();
|
||||
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements(); ) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (addr instanceof Inet4Address) {
|
||||
return addr.getHostAddress();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user