gpt4 book ai didi

java - 未找到 ManagedExecutorService

转载 作者:行者123 更新时间:2023-11-30 06:01:26 25 4
gpt4 key购买 nike

我对 Arquillian 和 ManagedExecutorService 存在问题。 Arquillian 无法找到默认的 ManagedExecutorService。异常(exception)是:

Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/DefaultManagedExecutorService

我正在使用 IntelliJ 并使用 Arquillian 1.4.0.FinalGlassFish Embedded 3.1 执行测试。

这是我的单元测试:

@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

最佳答案

我通过切换 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>

关于java - 未找到 ManagedExecutorService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52219227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com