0

We are upgrading our webapp to JSF 2.3.10, OWB 2.0.22, and TomEE 8.0.14. I realize we should move to Jakarta EE, but, for now, this is our tech stack.

I'm seeing stacktraces in the catalina logs concerning Default qualifiers. A snippet of one:

Caused by: javax.enterprise.inject.spi.DeploymentException: couldn't start owb context at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:263) at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:43) at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:974) at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:762) at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1340) 43 more Caused by: org.apache.openejb.OpenEJBRuntimeException: org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [com.inovis.catalogue.ui.hierarchy.SelcodeList] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default()] for injection into Field Injection Point, field name : selcodeList, Bean Owner : [SearchAction, WebBeansType:MANAGED, Name:searchAction, API Types:[java.io.Serializable,com.inovis.catalogue.ui.search.SearchAction,com.inovis.catalogue.ui.BaseAction,java.lang.Object], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any,javax.inject.Named,javax.faces.annotation.FacesConfig]] at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:200) at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:261) 47 more Caused by: org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [com.inovis.catalogue.ui.hierarchy.SelcodeList] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default()] for injection into Field Injection Point, field name : selcodeList, Bean Owner : [SearchAction, WebBeansType:MANAGED, Name:searchAction, API Types:[java.io.Serializable,com.inovis.catalogue.ui.search.SearchAction,com.inovis.catalogue.ui.BaseAction,java.lang.Object], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any,javax.inject.Named,javax.faces.annotation.FacesConfig]] at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:398) at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:196) 48 more Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [com.inovis.catalogue.ui.hierarchy.SelcodeList] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default()] for injection into Field Injection Point, field name : selcodeList, Bean Owner : [SearchAction, WebBeansType:MANAGED, Name:searchAction, API Types:[java.io.Serializable,com.inovis.catalogue.ui.search.SearchAction,com.inovis.catalogue.ui.BaseAction,java.lang.Object], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any,javax.inject.Named,javax.faces.annotation.FacesConfig]] at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60) at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:252) at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1231) at org.apache.webbeans.util.WebBeansUtil.validate(WebBeansUtil.java:1521) at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:1220) at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:1131) at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:323) 49 more

I've looked at several blogs and many questions/answers here on StackOverflow about configuring OWB2, Tomcat (TomEE+), and JSF2.3. Including: https://hantsy.gitbook.io/java-ee-8-by-example/jsf/jsf-activation

Apache OpenWebBeans(CDI) + Servlet, injection not working

https://devlearnings.wordpress.com/2011/05/15/apache-openwebbeans-cdi-from-standalone-to-webapp

OpenWebBeans + MyFaces + Tomcat = IllegalStateException

I've also added the extra dependencies to the TomEE/lib directory, found in the batch file, based on this site: https://lists.apache.org/thread/wct0r81bvsdbo7jbyqmw3x3d90h8s9jr

My configuration:

/META_INF/context.xml (Commented out due to org.apache.tomee.catalina.TomcatResourceFactory.create Can't create resource null -> java.lang.IllegalStateException: On a thread without an initialized context nor a classloader mapping a deployed app)

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!--    <Resource name="BeanManager"-->
<!--              auth="Container"-->
<!--              type="javax.enterprise.inject.spi.BeanManager"-->
<!--              factory="org.apache.webbeans.container.ManagerObjectFactory"/>-->
</Context>

/WEB-INF/beans.xml

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
       bean-discovery-mode="annotated"
       version="2.0">
</beans>

/WEB-INF/web.xml (snippet)

    <context-param>
        <param-name>org.apache.myfaces.RENDER_VIEWSTATE_ID</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <resource-env-ref>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

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

    <!--jsf-->
    <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>faces</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>faces</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

A snippet of our bean and the class it's injected into:

@FacesConfig(version=FacesConfig.Version.JSF_2_3)
@Default
@Named("selcodeList")
@SessionScope
public class SelcodeList extends BaseListAction implements Serializable {

@FacesConfig(version=FacesConfig.Version.JSF_2_3)
@Default
@Named("searchAction")
@SessionScoped
public class SearchAction extends BaseAction {

    @Inject
    private SelcodeList selcodeList;

I've even added a ConfigurationBean:

import javax.faces.annotation.FacesConfig;

@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class ConfigurationBean {
}

So, I suspect it's a configuration error, but I'm not sure where. However, based on the above references, everything seems to be in order. What else could cause the qualifier error?

Secondly, adding the @Default annotation explicitly seemed to help with other similar errors. I thought that annotation was implied in CDI beans?

Thank you for any help with this.

RandyB
  • 1
  • 2
  • 1
    RandyB, with tomee (web profile, plus and plume), there is no need to add external dependencies to make CDI and JSF work. Your SelcodeList bean is really annotated with as a SessionScoped CDI bean? Your code shows only a SessionScope annotation. – Paulo Araújo Apr 05 '23 at 19:16

1 Answers1

1
  1. Change the bean-discovery-mode="annotated" to bean-discovery-mode="all" in beans.xml file.
  2. Remove @FacesConfig(version = FacesConfig.Version.JSF_2_3) and @Default from SelcodeList and SearchAction
  3. Add @ApplicationScoped to ConfigurationBean
  4. Add implements Serializable to SearchAction bean
  5. Remove extra Apache OpenWebBeans dependencies from the TomEE/lib directory, don't remove libs provided by Apache TomEE.
శ్రీ
  • 143
  • 10