Springboot项目启动时自动打印访问地址
程序员文章站
2022-07-05 21:04:48
Springboot项目启动时自动打印访问地址在Springboot项目中每次启动完项目,手动在浏览器输入访问地址太麻烦了。在启动类中加入下方代码,就可高效地在控制台中单击URL访问项目了~示例代码:@SpringBootApplication@Slf4jpublic class WebApplication { public static void main(String[] args) throws UnknownHostException { Configurab...
Springboot项目启动时自动打印访问地址
在Springboot项目中每次启动完项目,手动在浏览器输入访问地址太麻烦了。在启动类中加入下方代码,就可高效地在控制台中单击URL访问项目了~
示例代码:
@SpringBootApplication
@Slf4j
public class WebApplication {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(WebApplication.class, args);
System.out.println("项目启动成功 *^_^* \n" + " .-------. ____ __ \n"
+ " | _ _ \\ \\ \\ / / \n" + " | ( ' ) | \\ _. / ' \n"
+ " |(_ o _) / _( )_ .' \n" + " | (_,_).' __ ___(_ o _)' \n"
+ " | |\\ \\ | || |(_,_)' \n" + " | | \\ `' /| `-' / \n"
+ " | | \\ / \\ / \n" + " ''-' `'-' `-..-' ");
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
if (StringUtils.isEmpty(path)) {
path = "";
}
log.info("\n----------------------------------------------------------\n\t" +
"Application is running! Access URLs:\n\t" +
"Local访问网址: \t\thttp://localhost:" + port + path + "\n\t" +
"External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
"----------------------------------------------------------");
}
}
关注下方,发送"01"获取更多相关学习教程。
本文地址:https://blog.csdn.net/rongbo91/article/details/109645729