I'm using JEE version 5.0.2. I'm calling a WebMethod in a @WebService annotated class. This annotated class calls a Stateless @EJB that contains the business logic (the implementation) of the WebMethod I'm calling.
My WebService class is defined as follows:
@WebService
HandlerChain(file = "MyXService_handle.xml")
public class MyXService {
@EJB(mappedName="MyXBean", beanName="MyXBean")
public MyXBean myXBean;
@WebMethod
public String sayHello(@WebParam(name="nTimes") int nTimes) {
return myXBean.sayHello(nTimes);
}
}
My EJB is defined as follows:
@Stateless(name="MyXBean", mappedName="MyXBean")
@TransactionManagement(TransactionManagementType.BEAN)
public class MyXBean {
@PersistenceContext name="persistence/my_PU", unitName="my_PU")
protected EntityManager entityManager;
public String sayHello(int nTimes) {
String s = "";
for (int i = 0; i < nTimes; i++) {
s += "Hello";
}
return s;
}
}
I'm getting the following error:
Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.my.domain.MyXService/myXBean@jndi: MyXBean@null@com.my.domain.MyXBean@Session@MyXBean into class com.sun.enterprise.webservice.JAXWSServlet
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:117)
at com.sun.web.server.J2EEInstanceListener.handleBeforeEvent(J2EEInstanceListener.java:259)
... 31 more
Caused by: javax.naming.NameNotFoundException: MyXBean#com.my.domain.MyXBean not found
at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:409)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:944)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:407)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:287)
... 34 more
|#]
The WebService class and the EJB are exactly in the same module in the same WAR. This WAR is being deployed in a Glassfish Server version 2.1.1. I only get this warning in the deploy log (server.log):
[#|2018-12-10T22:51:59.045+0100|WARNING|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=78;_ThreadName=Thread-946;_RequestID=bf2b9b34-5240-4eca-8b4b-9d16baad7c5b;|Unresolved <ejb-link>: MyXBean|#]
I'm following the Java EE 5 specification to implement all of this, so I'm trying to do my architecture "by the book".
I have no xml configuration concerning the beans. I was expecting all to work via the annotations but I'm getting the javax.Naming.NameNotFoundException explained above.
Am I missing something? I'm available to give more details if needed.
Thank you.
What I have tried:
I already tried to implement an interface as explained in here https: