javajakarta-ee

Jakarta faces issue: DI is not available


I am upgrading java to v17 and some servers to the latest versions of jakarta faces. When I start my server, I'm getting an error that I could use some help with...

SEVERE: Exception sending context initialized event to listener instance of class [com.sun.faces.config.ConfigureListener]
java.lang.IllegalStateException: CDI is not available
at com.sun.faces.util.Util.getCdiBeanManager(Util.java:1534)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:126)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3976)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4403)

I can't find a good answer about why I'm getting this error and have been struggling with it for several days now. Would anyone know how to resolve this?

Here are some details:

This is some of my classpath:

Is there any other information that would be relevant to share?


Solution

  • From the error it requires a CDI implementation, such as Weld or Apache OpenWebBeans.

    <!-- Weld for CDI support -->
            <dependency>
                <groupId>org.jboss.weld.servlet</groupId>
                <artifactId>weld-servlet-core</artifactId>
                <version>${weld.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>jakarta.el</groupId>
                        <artifactId>jakarta.el-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    

    Check my Jakarta EE 9 servlet template project, which provides the essential dependencies for Apache Tomcat and Eclipse Jetty when starting a Servlet container-based application, including Faces, REST support.