diff --git a/impl/src/main/java/com/sun/faces/util/Util.java b/impl/src/main/java/com/sun/faces/util/Util.java index 1129da3f8f..a342e086ef 100644 --- a/impl/src/main/java/com/sun/faces/util/Util.java +++ b/impl/src/main/java/com/sun/faces/util/Util.java @@ -1559,20 +1559,20 @@ public static BeanManager getCdiBeanManager(FacesContext facesContext) { result = (BeanManager) facesContext.getExternalContext().getApplicationMap().get(RIConstants.CDI_BEAN_MANAGER); } else { try { - CDI cdi = CDI.current(); - result = cdi.getBeanManager(); + InitialContext initialContext = new InitialContext(); + result = (BeanManager) initialContext.lookup("java:comp/BeanManager"); } - catch (Exception | LinkageError e) { + catch (NamingException ne) { try { InitialContext initialContext = new InitialContext(); - result = (BeanManager) initialContext.lookup("java:comp/BeanManager"); + result = (BeanManager) initialContext.lookup("java:comp/env/BeanManager"); } - catch (NamingException ne) { + catch (NamingException ne2) { try { - InitialContext initialContext = new InitialContext(); - result = (BeanManager) initialContext.lookup("java:comp/env/BeanManager"); + CDI cdi = CDI.current(); + result = cdi.getBeanManager(); } - catch (NamingException ne2) { + catch (Exception | LinkageError e) { } } }