SpringCloud—启动时获取当前的profiles

概述

在启动springboot的项目过程中,我们可能需要打印出活动的profiles。

@SpringBootApplication
@Slf4j
public class CompanyApplication {
    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(CompanyApplication.class, args);

        String[] activeProfiles = ctx.getEnvironment().getActiveProfiles();
        for (String profile : activeProfiles) {
            log.warn("Spring Boot 使用profile为:{}" , profile);
        }
    }
}

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注