2

I am trying to upgrade my JSF 1.1 project to JSF 2.3.9 and have implemented CDI on tomcat 9 following instructions from Balus C Install CDI in Tomcat

So I have valid dependencies, context.xml, beans.xml and listener added in web.xml as per instructions above.

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

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

My gradle dependencies are:

 api 'org.glassfish:javax.faces:2.3.9'
 implementation 'javax.enterprise:cdi-api:2.0'
 implementation 'org.apache.openwebbeans:openwebbeans-jsf:2.0.20'
 implementation 'javax.validation:validation-api:2.0.1.Final'

I also have pre-existing Jersey rest endpoints in my Project. The dependencies for that are:

implementation "org.glassfish.jersey.core:jersey-server:${jerseyVersion}"
implementation "org.glassfish.jersey.core:jersey-common:${jerseyVersion}"
implementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}"
api "org.glassfish.jersey.containers:jersey-container-servlet:${jerseyVersion}"
api "org.glassfish.jersey.media:jersey-media-multipart:${jerseyVersion}"
api "org.glassfish.hk2:hk2-api:2.6.1"

where my jerseyVersion is 2.36.

The project compiles correctly. But on starting tomcat, I get the following error:

July 20, 2022 9:28:01 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.apache.webbeans.servlet.WebBeansConfigurationListener]

org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.glassfish.hk2.api.ServiceLocator] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Constructor Injection Point, constructor name :  org.glassfish.hk2.utilities.GreedyResolver, Bean Owner : [GreedyResolver, WebBeansType:MANAGED, Name:null, API Types:[org.glassfish.hk2.api.JustInTimeInjectionResolver,java.lang.Object,org.glassfish.hk2.utilities.GreedyResolver], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:344)
at org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication(AbstractLifeCycle.java:137)
at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:103)
at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:99)

Am not a CDI JSF expert, but I assume this is CDI trying to scan all the managed beans on load and failing. Everytime I start tomcat, the error changes to the same error getting thrown for some other class from Jersey/HK2 dependencies.

Why is this happening? What is the solution for this? Can someone please guide me to a possible way to handle/resolve/correct this.

I also get below error later in the stack trace:

java.lang.RuntimeException: java.lang.IllegalStateException: It's not allowed to call getReference(Bean, Type, CreationalContext) before AfterDeploymentValidation
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:315)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4768)

But I think that's just my second listener (com.sun.faces.config.ConfigureListener) failing because the CDI did not complete successfully. And I assume this error will go away once I make CDI to behave correctly. Though please let me know if that is not the case. And would appreciate some guidance for this error as well.

Thanks!

Update

After updating bean-discovery-mode to annotated, I am still getting the same error:

July 23, 2022 11:52:05 AM 

org.apache.webbeans.servlet.WebBeansConfigurationListener doStart
SEVERE: An error occurred while starting application context path : [/MyApp]

July 23, 2022 11:52:05 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.apache.webbeans.servlet.WebBeansConfigurationListener]

org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.glassfish.hk2.api.ServiceLocator] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Constructor Injection Point, constructor name :  org.jvnet.hk2.internal.DynamicConfigurationServiceImpl, Bean Owner : [DynamicConfigurationServiceImpl, WebBeansType:MANAGED, Name:null, API Types:[org.glassfish.hk2.api.DynamicConfigurationService,java.lang.Object,org.jvnet.hk2.internal.DynamicConfigurationServiceImpl], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:344)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication(AbstractLifeCycle.java:137)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:103)
    at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:99)
    at org.apache.webbeans.servlet.WebBeansConfigurationListener.doStart(WebBeansConfigurationListener.java:197)
    at org.apache.webbeans.servlet.WebBeansConfigurationListener.contextInitialized(WebBeansConfigurationListener.java:86)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4768)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1783)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:814)
Vicky
  • 16,679
  • 54
  • 139
  • 232

0 Answers0