首页 > 解决方案 > Quarkus:quarkus:dev 目标无法正确使用在另一个模块中定义的 jax-rs 资源

问题描述

我有 2 个 Maven 模块。第一个定义了一个简单的 PingResource(下面的代码) 第二个(主)模块引用了第一个模块并使用 quarkus-maven-plugin 来 a)创建 uber jar,main-runner.jar b)通过 mvn quarkus:dev 启动应用程序

如果我通过“java -jar main-runner.jar”启动应用程序,则可以访问 ping 资源如果我使用“mvn quarkus:dev”,则会出现以下错误。

我想,在“quarkus:dev”期间如何解决 PingResource 是有某种联系的。我什至可以使用“@QuarkusTest”注释在第二个模块中测试 PingResource。第一个模块声明“META-INF/beans.xml”以允许 bean 发现。

知道有什么问题吗?

Listening for transport dt_socket at address: 5005
2020-02-07 09:01:34,655 INFO  [io.quarkus] (main) developer-test 1.0.0 (running on Quarkus 1.2.0.Final) started in 2.500s. Listening on: http://0.0.0.0:8080
2020-02-07 09:01:34,668 INFO  [io.quarkus] (main) Profile dev activated. Live Coding activated.
2020-02-07 09:01:34,668 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson]
2020-02-07 09:01:34,834 ERROR [org.jbo.res.res.i18n] (executor-thread-1) RESTEASY002005: Failed executing GET /v1/ping: org.jboss.resteasy.spi.InternalServerErrorException: RESTEASY003020: Bad arguments passed to public java.lang.String com.http.PingResource.hello()  ( )
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:191)
    at org.jboss.resteasy.core.MethodInjectorImpl.lambda$invoke$3(MethodInjectorImpl.java:122)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:616)
    at java.util.concurrent.CompletableFuture.uniApplyStage(CompletableFuture.java:628)
    at java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:1996)
    at java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:110)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:122)
    at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:594)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:468)
    at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:421)
    at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:363)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:423)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
    at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invoke$1(ResourceMethodInvoker.java:365)
    at java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:995)
    at java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2137)
    at java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:110)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:365)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:477)
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:252)
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:153)
    at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:363)
    at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:156)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:238)
    at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
    at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:120)
    at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:36)
    at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:85)
    at io.quarkus.runtime.CleanableExecutor$CleaningRunnable.run(CleanableExecutor.java:224)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2011)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1535)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1395)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:151)
    ... 38 more
@Path("/v1/ping")
public class PingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return Instant.now() + ": ok";
    }
}

更新:我尝试使用新的 Maven 项目 1.2.0.Final 再次重现该问题。它工作得很好。我创建了 2 个 maven 模块,一个仅声明了 jax-rs 资源(根本不依赖 quarkus,只是 javax-ee),第二个引用第一个并包括 quarkus 依赖项 + 它的 maven 插件。quarkus:dev 工作正常。所以第一个问题可能是一些与我们的“胖”库相关的独特问题,它使用 CDI 注入持久性、监控 servlet、记录器等。

标签: javamavenmaven-pluginresteasyquarkus

解决方案


推荐阅读