猿问

找不到 ManagedExecutorService

我对 Arquillian 和ManagedExecutorServices有问题。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;

        });

    }



}

如何ManagedExecutorService使用 Arquillian测试s?


HUX布斯
浏览 219回答 3
3回答

慕无忌1623718

我通过切换依赖项解决了它pom.xml:老的:<dependency>&nbsp; &nbsp; <groupId>org.glassfish.main.extras</groupId>&nbsp; &nbsp; <artifactId>glassfish-embedded-web</artifactId>&nbsp; &nbsp; <version>5.0</version>&nbsp; &nbsp; <scope>provided</scope></dependency>新的:<dependency>&nbsp; &nbsp; <groupId>org.glassfish.main.extras</groupId>&nbsp; &nbsp; <artifactId>glassfish-embedded-all</artifactId>&nbsp; &nbsp; <version>5.0</version>&nbsp; &nbsp; <scope>provided</scope></dependency>
随时随地看视频慕课网APP

相关分类

Java
我要回答