package com.summergao.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* 获取当前服务的IP端口
*
* @author SummerGao
*/
@Configuration
public class ServerConfig {
@Value("${tomcat.port}")
private Integer port;
@Value("${tomcat.contextPath}")
private String contextPath;
/**
* 项目获取当前服务的IP端口地址
*
* @return
*/
public String getUrl() {
InetAddress address = null;
try {
address = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return "http://" + address.getHostAddress() + ":" + port + "/" + contextPath;
}
}
最后
以上就是温柔香烟最近收集整理的关于springboot 项目获取当前服务的IP端口地址的全部内容,更多相关springboot内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复