i'm triyng to develop a simple web service in Java that used an EJB, with EJBs in jar file and WebServices in war file, both packaged in one ear. We use EjB 3.0 on JBOSS-AS 7.1.
Here my EJB class with its interface :
@Stateless
public class TestEjb implements ITestEjb {
public boolean authentifier(String login, String password) {
if(login.equals("nico") && password.equals("nr"))
return true;
else
return false;
}
}
@Local
public interface ITestEjb {
public boolean authentifier(String login, String password);
}
And here is my web service which inject the previous EJB :
//@Stateless
@WebService
@SOAPBinding(style = Style.RPC)
public class AuthentificationWS {
@EJB
private ITestEjb testEjb;
public boolean authentifier(String login,String password) {
return testEjb.authentifier(login, password);
}
}
The deployment works well but when i call my web service, the EJB is always null(error : java.nullpointerException).
So i tried to add a @Stateless
to my web Service to convert it to EJB but without success when i try to consume it by a web service client.
Then i tried to access Ejb by local jndi lookup like below, taking the local jndi url in JBOSS log :
final String jndi = "java:module/TestEjb!fr.test.ITestEjb";
testEjb = (ITestEjb) new InitialContext().lookup(jndi);
But it did not work.
Finally i tried with the global jndi url like below :
final String jndi = "ejb:Num-ear-1.0.0-SNAPSHOT/Num-ejb-1/TestEjb!fr.test.ITestEjb"
testEjb = (ITestEjb) new InitialContext().lookup(jndi);
And it works well !!
So, i don't understand why my webservice cannot access locally to its EJB by injection or local Jndi way?
TestEjb
andAuthentificationWS
in the same EAR? Are they in the same ejb-jar? – Philippe Marschall