I’m currently working on a Java multimodule project and want to reduce the coupling through DI.
As a minimal example I have two modules. Module A is the Clientside where I do all my Injects via Guice. Modula A calls classes in Module B which are mostly EJBs and inject themselves via @EJB annotation. To let module A call a Class in module B I use JNDI lookups. I now tried to get rid of JNDI and inject the classes in module B via guice, too. When I do that the @EJB doesn’t work anymore. Is there a solution to do this via guice?
I’m currently working on a Java multimodule project and want to reduce the coupling
Share
What you do is possible, but only for Test-scenarios, where you access your EJB from console. The real-app client code should never access the bean directly.
Also, though you can write a custom injection to get EJB resources injected, your bean will behave differently outside the EJB container (entities, resources, service-calls, interceptors, transaction). So generally spoken: Dont mix guice and ejb injection for production code.