0

I have a strange problem with EJB injection in the glassfish 3. Maybe I just not completely understand what I do :)

So this is a problem: My project consists of 2 modules that will be assembled with gradle.

  • Module A
  • Module B

Module A is a usual glassfish module that also works fine. Module B contains general purpose staff. Module B is also a dependency of A. Module A will be deployed to glassfish as a *.war archive and Module B is in the appropriate lib folder as *.jar archive:

module-a.war and somewere inside of it ../lib/module-b.jar

What I want is: Create in the Module B a "general purpose" stateless bean and use it in the Module A. But it doesn't work...

In the Module B I created a bean:

@Stateless
public class GeneralPurposeBean {}

and I try to use it in the Module A as follows:

...
@EJB
private GeneralPurposeBean genPurpBean;
...

So how I already mentioned the GeneralPurposeBean is in the *.jar

Each time when I try to use the bean it fails with following exception:

javax.ejb.CreateException: Could not create stateless EJB

When I move the bean to the Module A it works fine but I want share this bean with other modules, that will be developed in the future. Can someone explain to me what is wrong here? So the bean will be recognized but it can't be created. What I found out through debugging is that

JCDIServiceImpl#_createJCDIInjectionContext

Doesn't recognize the bean as an enterprise bean. So everything in the *.war that directly accessible will be properly created but not what lies in the *.jar's.

3
  • 1
    Put them in a unique EAR (Enterprise ARchive) and try again
    – Riadh
    Apr 29, 2016 at 16:38
  • Try creating an interface, annotated with @Remote, that your GeneralPurposeBean implements. Then, on your ModuleA, use it in the following way: @EJB GeneralPurposeBeanInterface genPurpBean;. Apr 29, 2016 at 21:28
  • Possible duplicate of Packaging EJB in JavaEE 6 WAR vs EAR Apr 30, 2016 at 18:06

1 Answer 1

0

For the case someone has the same problem:

If you treat one of your modules as a dependency and this module contains EJB beans you want be injected the solution for my problem was to put /META-INF/beans.xml file into the module. Otherwise container doesn't recognize the beans as EJB.

That's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.