如何使用 Spring 引导以编程方式确定当前活动配置文件

How to determine programmatically the current active profile using Spring boot

有没有办法以编程方式在我的 bean 中获取当前活动配置文件?

您的应用程序启动或只是原始应用程序都没有关系 Spring。刚好可以将 org.springframework.core.env.Environment 注入到您的 bean 中。

@Autowired
private Environment environment;
....

this.environment.getActiveProfiles();