This questiong is regarding Java EE 6, using glassfish v3 embedded-all.
I have a unit test that uses EJBContainer to test my stateless EJB. Problem is I'm having trouble looking up the EJB (remote) using JNDI:
setup() {
ctx = EJBContainer.createEJBContainer().getContext();
}
...
test() {
BookService bookService = (BookService)ctx.lookup("java:global/BookServiceEJB!com.something.service.BookService");
...
}
@Stateless
public class BookServiceEJB implements BookService {
...
}
@Remote
public interface BookService {
...
}
gives the exception:
javax.naming.NamingException: Lookup failed for 'java:global/BookServiceEJB!com.something.service.BookService' in SerialContext [Root exception is javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found]
...
caused by: javax.naming.NameNotFoundException: BookServiceEJB!com.something.service.BookService not found
I have tried several JNDI resource paths:
e.g.
java:global/BookServiceEJB
java:global/BookService
even:
java:global/BookShelf-1.0-SNAPSHOT/BookServiceEJB
etc...
nothings works
I do not have any xml deployment files configured, only a persistence.xml
in META-INF.
The test is using maven surefire:
mvn clean test
Any help is greatly appreciated!
Note: a full deploy to Glassfish server works (using appclient, and @EJB
injection)