在SpringBoot的启动类中引入下面的代码,代码引入后,直接启动即可
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(SpringbootTestApplication.class, args);
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String property = env.getProperty("server.servlet.context-path");
String path = property == null ? "" : property;
System.out.println(
"n" +
"----------------------------------------------------------nt" +
"Application is running! Access URLs:nt" +
"Local: tthttp://localhost:" + port + path + "nt" +
"External: thttp://" + ip + ":" + port + path + "n" +
"----------------------------------------------------------n");
}
注意
项目要配置一下端口号,否则打印的端口号会为null。



