How to inject config properties inside a Quarkus extension

935 views Asked by At

I'm trying to move the following (working) code to an extension:

@WebListener
public class StartupListener implements ServletContextListener {

    @ConfigProperty(name = "javax.faces.PROJECT_STAGE")
    String projectStage;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        sce.getServletContext().setInitParameter("javax.faces.PROJECT_STAGE", projectStage);
    }

}

When I move this code to an extension runtime module the property is not resolved (it is null).

The extension source code can be found here.

1

There are 1 answers

0
rmpestano On BEST ANSWER

Managed to make it work programatically via config provider:

@Override
public void contextInitialized(ServletContextEvent sce) {
    Config config = ConfigProvider.getConfig();
    String projectStage = config.getValue("javax.faces.PROJECT_STAGE", String.class);
    sce.getServletContext().setInitParameter("javax.faces.PROJECT_STAGE", projectStage);
}