This question is about Java EE 6 using Glassfish v3 embedded-all .
I have a unit test that uses an EJBContainer to test my headless EJB. The problem is that I am having problems finding an 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 an 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 tried several JNDI resource paths:
eg.
java:global/BookServiceEJB java:global/BookService
even
java:global/BookShelf-1.0-SNAPSHOT/BookServiceEJB
etc...
nothing works
I do not have xml deployments configured , but only persistence.xml in META-INF.
The test uses maven surefire:
mvn clean test
Any help is much appreciated!
Note : full deployment on Glassfish server works (using appclient and @EJB )
java-ee java-ee-6 glassfish-3 jndi
Ju
source share