Injecting @Stateless EJB in Arquillian tests

北城余情 提交于 2019-12-08 05:33:57

问题


A weird problem when running Arquillian test. If I try to use an EJB annotated with @Stateless, I get this error:

org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [MyEjbRemote] with qualifiers [@Default] at injection point [[field] @Inject private com.org.app.ejb.InjectionTest.ejb]

I have the following test class + deployment for the Arquillian:

@RunWith(Arquillian.class)
public class InjectionTest extends TestCase {

  @Inject
  private MyEjbRemote ejb;

  @Deployment
  public static JavaArchive createDeployment() {
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar").addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
    jar.addClass(MyEjbRemote.class);
    jar.addClass(MyEjb.class);
  }

  @Test
  public void checkInjection() {
    TestCase.assertNotNull(ejb);
  }
}

The EJB looks like this:

@Stateless
@Default
public class MyEjb implements MyEjbRemote {
  public MyEjb() {
  }
}

The remote interface just has @Remote annotation.

If I change the @Stateless to @Named, it works. But I wan to use the @Stateless.

pom.xml:

<dependencies>
  <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
  </dependency>
  <dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-container</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jboss.arquillian</groupId>
      <artifactId>arquillian-bom</artifactId>
      <version>1.1.9.Final</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

来源:https://stackoverflow.com/questions/35743240/injecting-stateless-ejb-in-arquillian-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!