Problem with EJB 3.1 with CDI bean when running JUnit

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) 
+3
java junit java-ee-6 cdi
source share

No one has answered this question yet.

See similar questions:

7
How to embed @Named bean in Junit test

or similar:

272
Injecting Mockito mocks Spring bean
nine
CDI EJB Injection results in a NullPointerException
5
Stateless EJB implementation with @Inject in CDI Weld ManagedBean (JSF 1.2 EJB application on jboss 6 AS)
2
How to embed EJB in an abstract CDI class?
one
NullpointerException Arkillian Ask Test
one
I want to use knitwear to provide a calm webservice, but I can't add beans in the spring to the knitwear resource class, can I?
one
CDI and JaxWS and EJB in profile of freedom 8.5.5.0
0
CDI with ejb 3.1, glass veil welding machine v3.0.1
0
Junit test with OpenEJB Embedded Container and CDI
0
@EJB and @Inject causing NPE in Glassfish 3.1.2 and Java 6

All Articles