I created EJB3.1 and introduced the CDI bean using @inject, but faced with some problems, while unit testing, however, when testing from the servlet of its performance. I have beans.xml in the WEB-INF folder. The following is the EJB code:
@Stateless public class CdiUsingEjb { @Inject private HelloServletCDIPojo helloServletCDIPojo; public String greet() { assert helloServletCDIPojo != null; return helloServletCDIPojo.from(); } }
Below is my CDI bean:
public class HelloServletCDIPojo { public String from() { return "from HelloServletStateless CDI"; } }
I created a JUnit class:
public class CdiUsingEjbTest { @EJB private CdiUsingEjb cdiUsingEjb; @Before public void setUp() throws Exception { EJBContainer.createEJBContainer().getContext().bind("inject", this); } @Test public void test() { assertNotNull(cdiUsingEjb); } }
When I run this JUnit test, I got the following error.
org.apache.openejb.OpenEjbContainer$AssembleApplicationException: org.apache.openejb.OpenEJBException: Creating application failed: /Users/prasannakumar/freelanceWorkspace/javaWorkspace/TomEEExamples: couldn't start owb context at org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:310) at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:56) at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:43) at in.jugchennai.prassee.ejb.HelloServletStatelessEJBTest.setup(HelloServletStatelessEJBTest.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601)
prassee
source share