Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with EJB 3.1 injected with CDI bean while running JUnit
    primarykey
    data
    text
    <p>I created a EJB3.1 and injected CDI bean using the @inject but facing some issues while unit testing however when tested from the servlet its working fine. I have the beans.xml in the WEB-INF folder. Below is my EJB code:</p> <pre><code>@Stateless public class CdiUsingEjb { @Inject private HelloServletCDIPojo helloServletCDIPojo; public String greet() { assert helloServletCDIPojo != null; return helloServletCDIPojo.from(); } } </code></pre> <p>Below is my CDI bean:</p> <pre><code>public class HelloServletCDIPojo { public String from() { return "from HelloServletStateless CDI"; } } </code></pre> <p>I created a JUnit class:</p> <pre><code>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); } } </code></pre> <p>When I run this JUnit test I got the following error. </p> <pre><code>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) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload