java - How do I enable EJB injection in dependent projects -


I have a Java EE project that instantates an instance of an object from a dependent project. The dependent project now wants to make and eject its EJB in one of its classes. The dependent project does not refer to the original project, but should run inside the original project's container.

When I apply the original project, I see the message in the log that has been searched in conjunction with my service bean with the remaining beans in the parent's project:

  2014-04-28 T21: 30: 56.240-0400 | INFO: EJB5181: Portable JNDI name for EJB dependency project SBBAN etc.  

But then when I try to apply that bean to a dependent project using @EJB annotation, then nothing happens (it has just been left as zero).

I am trying to explain how to properly configure these projects, so that I can use EJB and JPA in the dependent project, but I think I do not know the correct search term, since I think that they do not have anything like solving this issue. I am adding the same Mewen dependencies to the dependent project as I do in the original project, and Eclipse feels good with comments;

EDIT: There is a thick outline of code I'm working with.

Parents

  Public category parents project class {@EJB ParentServiceBean psb; Public Zero Cat () {psb.doStuff (); // No problem SomeDependentClass sdc = New SomeDependentClass (); Sdc.baz (); }}  

dependent project

  public class SomeDependentClass {Private other WT class ADC; Public SomeDependentClass () {adc = New OtherDependentClass (); } Public Zero Falcon () {adc.foo (); }} Public Sector Other WTA Class {@EJB DependentProjectServiceBean dpsb; Foo () {dpsb.bar (); // NULL POINTER EXCEPTION}} @Stateless Public Class DependentProjectServiceBean {Public Zero Times () {// times}} 

You can not inject EJB (which is not itself EJB or JSF managed bean) using EJB annotations inside a simple class. The simplest solution is to convert your dependent project into the EJB project. If you can not do this, you can try to inject it using the manual JNDI lookup, here is a sample code:

  // Recover the initial reference for JNDI. Reference Reference = New Initial Concert (); // Recover the home interface using a JNDI lookup DPSB = (DependentProjectServiceBean) context.lookup ("java: comp / env / ejb / DependentProjectServiceBean");  

Replace java: comp / env / ejb / DependentProjectServiceBean your JNDI path


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -