2

I'm using a Tomcat 8 (8.0.30), OpenWebBeans 1.6.2, JSF Mojarra 2.2.12, and OmniFaces 1.8. I decided that I wanted to upgrade OmniFaces to a later version. After 2.0 it seems to require CDI, but when starting the Tomcat (with OmniFaces 2.2) I get the error below. According to OmniFaces' compatibility Matrix, Tomcat+Mojarra+OWB should work with 8.0.30+2.2.12+1.6.2.

I've tried with 2.0 as well, with the same error. In 2.1 I got another issue, but I just assumed it was something fixed for 2.2 since the behaviour there is the same as in 2.0. I also get the same issue with the 2.3-RC1.

Is there something specific that needs to be done to get OmniFaces to recognise that I'm running CDI? Is it likely a bug in OmniFaces?

I've created a very small sample app to replicate this problem, so I am certain there's nothing else in our main application that's interfering.

mar 22, 2016 10:57:46 FM org.apache.webbeans.lifecycle.AbstractLifeCycle bootstrapApplication
INFO: OpenWebBeans Container has started, it took [447] ms.
mar 22, 2016 10:57:46 FM org.omnifaces.ApplicationListener checkCDIAvailable
SEVERE: 
????????????????????????????????????????????????????????????????????????????????
?                         ??     ?                                             ?
?    ?                  ?????    ? OmniFaces failed to initialize!             ?
?   ????               ??????    ?                                             ?
?   ??????            ???????    ? This OmniFaces version requires CDI, but    ?
?   ???????          ???????     ? none was found on this environment.         ?
?    ???????????????????????     ?                                             ?
?    ???????????????????????     ? OmniFaces 2.x requires a minimum of JSF 2.2.?
?     ?????????????????????      ? Since this JSF version, the JSF managed bean?
?     ?????????????????????      ? facility @ManagedBean is semi-official      ?
?     ??????????????????????     ? deprecated in favour of CDI. JSF 2.2 users  ?
?     ??????????????????????     ? are strongly encouraged to move to CDI.     ?
?     ??????????????????????     ?                                             ?
?    ???????????????????????     ? OmniFaces goes a step further by making CDI ?
?    ????????????????????????    ? a REQUIRED dependency next to JSF 2.2. This ?
?    ????????????????????????    ? not only ensures that your web application  ?
?   ???????????????? ????????    ? represents the state of art, but this also  ?
?   ?????????????????????????    ? makes for us easier to develop OmniFaces,   ?
?   ??????????????????????????   ? without the need for all sorts of hacks in  ?
?   ??????????????????????????   ? in order to get OmniFaces to deploy on      ?
?  ????????????????????????????  ? environments without CDI.                   ?
?  ????????????????????????????  ?                                             ?
?  ????????????????????????????  ? You have 3 options:                         ?
?????????????????????????????????? 1. Downgrade to OmniFaces 1.x.              ?
?????????????????????????????????? 2. Install CDI in this environment.         ?
?????????????????????????????????? 3. Switch to a CDI capable environment.     ?
??????????????????????????????????                                             ?
?????????????????????????????????? For additional instructions, check          ?
?????????????????????????????????? http://omnifaces.org/cdi                    ?
??????????????????????????????????                                             ?
????????????????????????????????????????????????????????????????????????????????
mar 22, 2016 10:57:46 FM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.omnifaces.ApplicationListener
java.lang.ExceptionInInitializerError
    at org.omnifaces.ApplicationListener.checkCDIAvailable(ApplicationListener.java:74)
    at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:58)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI.
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:99)
    at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:49)
    ... 11 more
Caused by: java.lang.IllegalStateException: javax.naming.NamingException: Cannot create resource instance
    at org.omnifaces.util.JNDI.lookup(JNDI.java:95)
    at org.omnifaces.config.BeanManager.<init>(BeanManager.java:95)
    ... 12 more
Caused by: javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.omnifaces.util.JNDI.lookup(JNDI.java:90)
    ... 13 more

Here is the pom.xml I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>se.app.testapp</groupId>
    <artifactId>sampleapp</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-impl</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-jsf</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-el22</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-web</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.2.12</version>
        </dependency>
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <type>jar</type>
            <classifier>sources</classifier>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <type>jar</type>
        </dependency>

    </dependencies>
</project>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Robin
  • 63
  • 6
  • Does OWB work without OmniFaces? Root cause tells CDI BeanManager cannot be found in JNDI which will happen if you didn't register it in context.xml for Tomcat, but then you would already be unable to use CDI in its entirety, even without OmniFaces. If you have liberty in choosing CDI impl, for Weld you can find full instructions in the link in the error message. – BalusC Mar 22 '16 at 10:17
  • Yes, OWB works fine otherwise, been running it for quite some time since we changed from Weld. No issues. I don't have a BeanManager registered in a context.xml. Is that supposed to be needed? I can still run both my sample application and our full application with OWB with no issues. – Robin Mar 22 '16 at 10:49
  • FYI: I just made a successful test pass for OmniFaces 2.3 on Tomcat 8.0.32+OWB 1.6.2, I noticed I forgot those in [compatibility matrix](https://github.com/omnifaces/omnifaces/wiki/Compatibility-Matrix). Thanks for heads up! – BalusC Mar 22 '16 at 12:27

1 Answers1

0

Cause of your exception is:

java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI.

In other words, CDI BeanManager is not registered in JNDI during context initialization of OmniFaces. Normally, Tomcat has read-only JNDI and any new JNDI resources have to be supplied via webapp's /META-INF/context.xml. For Weld, this is detailed How to install CDI in Tomcat? and for OpenWebBeans you need the below one:

<Context>
    <Resource name="BeanManager"
        auth="Container"
        type="javax.enterprise.inject.spi.BeanManager"
        factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>

Additionally, for OWB you also need to explicitly register its context listener in webapp's /WEB-INF/web.xml in order to guarantee that it is initialized before OmniFaces.

<listener>
    <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>

Otherwise you may get an exception which looks like below when OmniFaces @Eager starts to initialize the application scoped beans:

java.lang.IllegalStateException: It's not allowed to call getBeans(Type, Annotation...) before AfterBeanDiscovery

Even though you already specified OmniFaces 2.2, I'd like to add a note for future readers that a minimum of OmniFaces 2.1 is required in order to peacefully work together with OWB manually installed on Tomcat (OmniFaces 2.0 works fine on TomEE), see also issue 133 which fixed 2 main issues as to initialization ordering and @Inject being unavailable in @WebListener.


Update: the "How to install CDI in Tomcat?" article has just been updated with instructions for OpenWebBeans.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Sorry that I'm a bit late, but just wanted to actually say that this fixed the issue and mark it as resolved! – Robin Sep 28 '16 at 08:35