Search code examples
javaquarkussupersonic

How to inject config properties inside a Quarkus extension


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.


Solution

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