Bernd Franke
Bernd Franke

Reputation: 21

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:

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.

Upvotes: 0

Views: 514

Answers (2)

Bernd Franke
Bernd Franke

Reputation: 21

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!

Upvotes: 0

Baptista
Baptista

Reputation: 148

Download weld-servlet.jar and put into the library of your project, or better, why you are not using wildfly? He carry all jars to run cdi in your aplication.

Upvotes: 0

Related Questions