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"));
    }

}

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页