启动类下输出控制面板直接打印
@Slf4j
@SpringBootApplication
public class Springboot03Application {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext context = SpringApplication.run(Springboot03Application.class, args);
// 获取app的 访问地址
Environment environment = context.getBean(Environment.class);
//environment.getProperty("server.servlet.context-path") 应用的上下文路径,也可以称为项目路径
String host = InetAddress.getLocalHost().getHostAddress();
String port = environment.getProperty("server.port");
String path = environment.getProperty("server.servlet.context-path");
if (StringUtils.isEmpty(path)) {
path = "";
}
log.info("\n访问地址:http://{}:{}{}", host, port, path);
System.out.println("\n访问地址:http://" + host + ":" + port + path);
System.out.println(port);
}
}
标签:String,url,入口,environment,host,context,path,port,springboot
From: https://www.cnblogs.com/liwenfeng/p/17574966.html