问题
I have spring-ws deployed in my server. There is some task every day which should write ip adress and the port of server where this application run. How I can get this information ? I try InetAddress
but with no success. There is no port.
回答1:
Getting a hold of the servletRequest should be enough to put you on track to get the IP address.
TransportContext ctx = TransportContextHolder.getTransportContext();
HttpServletConnection conn = (HttpServletConnection )ctx.getConnection();
HttpServletRequest request = conn.getHttpServletRequest();
Use this code in an interceptor defined on your ws. Now you can simply call
request. getRemoteAddr();
to get the IP.
来源:https://stackoverflow.com/questions/9114141/how-to-get-ip-adress-and-port-in-web-service