未找到 ManagedExecutorService
ManagedExecutorService not found
我对 Arquillian 和 ManagedExecutorService
s 有疑问。 Arquillian 无法找到默认值 ManagedExecutorService
。例外是:
Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/DefaultManagedExecutorService
我正在使用 IntelliJ 并使用 GlassFish Embedded 3.1
和 Arquillian 1.4.0.Final
.
执行测试
这是我的单元测试:
@Slf4j
@RunWith(Arquillian.class)
public class WorkhorseTest {
@Inject
private Workhorse workhorse;
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClass(Workhorse.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
public void testExecution() throws Exception {
final Future<Integer> result = workhorse.execute();
result.get(1, TimeUnit.MINUTES);
log.info("Executed...");
}
}
这是 EJB:
@Slf4j
@Singleton
public class Workhorse {
@Resource
private ManagedExecutorService mes;
public Future<Integer> execute() {
return mes.submit(() -> {
log.info("Hello from a Runnable");
return 5;
});
}
}
如何使用 Arquillian 测试 ManagedExecutorService
s?
我通过在 pom.xml
中切换依赖项解决了它:
旧:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-web</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
新:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
我对 Arquillian 和 ManagedExecutorService
s 有疑问。 Arquillian 无法找到默认值 ManagedExecutorService
。例外是:
Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/DefaultManagedExecutorService
我正在使用 IntelliJ 并使用 GlassFish Embedded 3.1
和 Arquillian 1.4.0.Final
.
这是我的单元测试:
@Slf4j
@RunWith(Arquillian.class)
public class WorkhorseTest {
@Inject
private Workhorse workhorse;
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClass(Workhorse.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
public void testExecution() throws Exception {
final Future<Integer> result = workhorse.execute();
result.get(1, TimeUnit.MINUTES);
log.info("Executed...");
}
}
这是 EJB:
@Slf4j
@Singleton
public class Workhorse {
@Resource
private ManagedExecutorService mes;
public Future<Integer> execute() {
return mes.submit(() -> {
log.info("Hello from a Runnable");
return 5;
});
}
}
如何使用 Arquillian 测试 ManagedExecutorService
s?
我通过在 pom.xml
中切换依赖项解决了它:
旧:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-web</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
新:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>