Java:SpringBoot启动时打印当前端口

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class Application {
     

    public static void main(String[] args) {
     
        ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);

        Environment environment = context.getBean(Environment.class);

        System.out.println("访问链接:http://localhost:" + environment.getProperty("local.server.port"));
    }

}

你可能感兴趣的:(java)