运行Arquillian测试时出现的奇怪问题。如果我尝试使用带@Stateless注释的EJB,我会收到此错误:
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]
我有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);
}
}
EJB看起来像这样:
@Stateless
@Default
public class MyEjb implements MyEjbRemote {
public MyEjb() {
}
}
远程接口只有@Remote注释。
如果我将 @Stateless 更改为 @Named ,则可以。但我想使用@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>
答案 0 :(得分:1)
为了测试非单例的无状态 EJB 的注入,您需要部署到嵌入式容器。
我遇到了同样的问题,这篇博文为我指明了正确的方向。 https://blog.payara.fish/how-to-test-applications-with-payara-server-micro-with-arquillian
我的工作 pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.6.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-all</artifactId>
<version>5.2020.4</version>
<scope>test</scope>
</dependency>
</dependencies>