效果图
方法
在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" +
"----------------------------------------------------------\n\t" +
"Application is running! Access URLs:\n\t" +
"Local: \t\thttp://localhost:" + port + path + "\n\t" +
"External: \thttp://" + ip + ":" + port + path + "\n" +
"----------------------------------------------------------\n");
}
注意
项目要配置一下端口号,否则打印的端口号会为null。