@Override
  public void contextInitialized(ServletContextEvent sce) {

    ServletContext context = sce.getServletContext();
    cdiContainer = (CdiContainer) context.getAttribute("org.ops4j.pax.cdi.container");
    cdiContainer.start(context);
    WeldManager manager = cdiContainer.unwrap(WeldManager.class);

    CdiInstanceFactoryBuilder builder = new CdiInstanceFactoryBuilder(manager);
    @SuppressWarnings("unchecked")
    Map<String, Object> attributes =
        (Map<String, Object>) context.getAttribute("org.ops4j.pax.web.attributes");
    if (attributes != null) {
      attributes.put("org.ops4j.pax.cdi.ClassIntrospecter", builder);
      log.info("registered CdiInstanceFactoryBuilder for Undertow");
    }
    context.setAttribute("org.ops4j.pax.cdi.BeanManager", cdiContainer.getBeanManager());

    JspFactory jspFactory = JspFactory.getDefaultFactory();
    if (jspFactory != null) {
      JspApplicationContext jspApplicationContext = jspFactory.getJspApplicationContext(context);

      jspApplicationContext.addELResolver(manager.getELResolver());
      jspApplicationContext.addELContextListener(new WeldELContextListener());
    }
    super.contextInitialized(sce);
  }