I am trying to enter a bean located in another jar file, and then the bean that I am trying to enter. Both beans are just basic @Stateless beans with local and remote interfaces. If i use normal injection
@EJB IBean injectedBean;
or
@EJB IBeanLocal injectedBean;
I get a NullPointerException when deploying the application.
If I use:
@EJB(mappedName="Bean") IBean injectedBean;
or
@EJB(mappedName="Bean") IBeanLocal injectedBean;
everything works, and JBoss does not create deployment errors.
Maybe I'm using JBoss 5.
The bean class that I introduced is declared as:
@Remote public interface IBean @Local public interface IBeanLocal extends IBean @Stateless(name = "Bean") public class Bean implements IBean, IBeanLocal
My problem is that, as stated in the documentation, the mappedName property is vendor-specific. Is there any other way I can get this to work?
SOLVE:
I managed to solve the problem.
The problem was that I tried to deploy both banks separately, which meant that everyone would get their own ClassLoader in JBoss so that they could not find each other and throw a NullPointerException when trying to insert a bean.
It was decided to add cans to the ear and add META-INF containing application.xml, which looks like this:
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> <display-name>Simple example of application</display-name> <module> <ejb>ejb1.jar</ejb> </module> <module> <ejb>ejb2.jar</ejb> </module> </application>
I also had to modify some JNDI searches that I did to fit the new structure by adding an ear name in front of the classes: "ear-name / bean"
After that, I just added cans to my ear, and everything was fine.