Skip to content

Instantly share code, notes, and snippets.

@talentestors
Last active March 11, 2025 02:56
Show Gist options
  • Select an option

  • Save talentestors/fc5b7f046fa93cddd428fc66830fa875 to your computer and use it in GitHub Desktop.

Select an option

Save talentestors/fc5b7f046fa93cddd428fc66830fa875 to your computer and use it in GitHub Desktop.
In the Spring Boot startup class, the URI address of the application is output and the org.fusesource.jansi library is used to add color to the console output.
@Slf4j
@SpringBootApplication
public class SpringApp {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(App.class, args);
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.hasLength(path)) {
path = "";
}
log.info(new Ansi().fgGreen().a("""
\n
\t---------------------------------------------------------------
\t\tApplication is running! Access URLs:
\t\tLocal 访问网址: \t\thttp://localhost:{}{}
\t\tExternal 访问网址: \thttp://{}:{}{}
\t---------------------------------------------------------------
""").reset().toString(), port, path, ip, port, path);
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
log.info("当前项目进程号:{}", jvmName.split("@")[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment