Search code examples
jakarta-eeglassfishcdipayara

Loading CDI beans in different JARs with Payara 4.1.1


we are currently porting our JEE 6 application (WAR deployment) from GF 3.1 to Payara 4.1.1. We are using EJBs and CDI beans. They are packaged in different jar files. I am facing the problem the CDI beans that are located in another jar file cannot be found. Each jar file has its own META-INF/beans.xml and there is also one for the WAR (WEB-INF/beans.xml) archive. I already tried the following steps:

  • adopt beans.xml (bean-discovery-mode="all")
  • deploy the WAR inside of and EAR deployment.
  • changed annotations that changed with CDI 1.1
  • updated all libraries to the latest version (richfaces, guava, eclipselink, ...) to meet the JEE 7 requirements

Does anybody know if there is general bug in Glassfish/Payara 4.1.1?

Thx, Bernd

Unfortunately that did not help. I did some more investigations and it seems like only "some" beans cannot be injected or retrieved from the BeanManager correctly. Here the class hierarchy that does not work:

`// AllwaysFalse is our own annotation.
@AllwaysFalse
@Named
public class AllwaysFalseRemoteCondition<E extends IStandardEntity>
         extends ConditionBase<javax.persistence.criteria.Predicate, E>
         implements RemoteCondition<javax.persistence.criteria.Predicate, E>      
{
…
}

// The abstract base class
public abstract class ConditionBase<R, T extends IStandardEntity> implements      Condition<R, T> {
}

// The base interface
public interface RemoteCondition<T, E extends IStandardEntity> extends  Condition<T, E> {

}

public interface Condition<T, E extends IStandardEntity> extends Part<ConditionDescriptor> {
…
}

If I change the class above to:

public class AllwaysFalseRemoteBotCondition<E extends IStandardEntity> {
}

The injection works.

If I try to inject the beans via the BeanManager the getBeans() method does not work if I do a type based search:

`BeanManager bm = getBeanManager();
    Set<Bean<?>> beans = bm.getBeans(clazz, annotations);

If I provide the interface class in the "class" parameter the return value is always null.


Solution

  • Solution:

    Set<Bean<?>> beans = bm.getBeans(
        new TypeLiteral<RemoteCondition<javax.persistence.criteria.Predicate,?>>() {}
        .getType(), 
        new AnnotationLiteral<AlwaysFalse>(){}
    

    The TypeLiteral solved the problem! Thanks to Payara support!