如何以编程方式确定Quarkus中的当前活动配置文件

ago*_*cal 3 quarkus

在《 Quarkus 应用程序配置指南》中,它提到了如何使用配置文件(例如%dev.quarkus.http.port=8181)配置应用程序。

But is there a way to access a Profile (or Environment) API so I can log the active profiles ? For example something like Spring:

@ApplicationScoped
public class ApplicationLifeCycle {

    private static final Logger LOGGER = LoggerFactory.getLogger("ApplicationLifeCycle");

    @Inject Environment env;

    void onStart(@Observes StartupEvent ev) {
        LOGGER.info("The application is starting with profiles " + env.getActiveProfiles());
    }
Run Code Online (Sandbox Code Playgroud)

A.C*_*ova 11

该方法ProfileManager.getActiveProfile()已被弃用。您应该使用:ConfigUtils.getProfiles()代替。

方法:

public static List<String> getProfiles() {
     return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getProfiles();
}
Run Code Online (Sandbox Code Playgroud)

PD:在 Quarkus 上测试v2.16.1.Final


Rom*_*cau 5

ProfileManager.getActiveProfile()?

  • 不幸的是,`ProfileManager.getActiveProfile()` 已被弃用(从 2.16.2.Final 开始,可能更早),所以我们又回到了原点。=( (3认同)