我正在使用Quarkus 1.0.1.Final
(我很陌生),Kotlin 1.3.61
和Gradle 6.0.1
做概念验证。
我从一个非常简单的资源开始:
@Path("/comments")
class ExampleResource(@Context val uri: UriInfo) {
private val logger = KotlinLogging.logger { }
@GET
@Produces(MediaType.APPLICATION_JSON)
fun hello(@Context request: Request): Response {
logger.info { "${request.method} ${uri.path}" }
return Response.ok().entity(Comment(post = "hello", content = "world!")).build()
}
}
...但是我遇到了这个问题(使用javax.ws.rs.core.UriInfo
的简单构造函数注入):
14:24:11,924 INFO [org.jbo.threads] JBoss Threads version 3.0.0.Final
14:24:13,241 ERROR [io.qua.dev.DevModeMain] Failed to start Quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:850)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:220)
at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:106)
at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:251)
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 io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:941)
at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
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:1426)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:472)
at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:404)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:212)
... 14 more
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:157)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:177)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:95)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:850)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:220)
at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:106)
at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:251)
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 io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:941)
at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
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:1426)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:472)
at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:404)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:212)
... 14 more
at io.quarkus.builder.Execution.run(Execution.java:108)
at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:121)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:130)
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:111)
... 3 more
Caused by: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:850)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:220)
at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:106)
at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:251)
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 io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:941)
at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
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:1426)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.ws.rs.core.UriInfo and qualifiers [@Default]
- java member: org.acme.resource.ExampleResource#<init>()
- declared on CLASS bean [types=[org.acme.resource.ExampleResource], qualifiers=[@Default, @Any], target=org.acme.resource.ExampleResource]
at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:472)
at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:404)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:212)
... 14 more
我已经阅读了有关同一主题的一些答案,但到目前为止我还没有找到任何解决方法。
更新:将uri
作为类成员使用lateinit var
是有效的,所以我认为这仅对Quarkus很奇怪:
@Path("/comments")
class ExampleResource(val service: ExampleService) {
private val logger = KotlinLogging.logger { }
@Context
private lateinit var uri: UriInfo
// ...
}
据我所知,allOpen
的配置和所有依赖项对于Gradle脚本来说都可以正常使用:
dependencies {
implementation enforcedPlatform("io.quarkus:quarkus-universe-bom:${property("quarkus.version")}") // quarkus.version = 1.0.1.Final
implementation "io.github.microutils:kotlin-logging:1.7.8"
implementation "io.quarkus:quarkus-kotlin"
implementation "io.quarkus:quarkus-resteasy-jsonb"
implementation "io.quarkus:quarkus-smallrye-openapi"
implementation "org.jetbrains.kotlin:kotlin-stdlib"
testImplementation "io.quarkus:quarkus-junit5"
testImplementation "io.rest-assured:rest-assured"
}
allOpen {
annotation("io.quarkus.test.junit.QuarkusTest")
annotation("javax.enterprise.context.ApplicationScoped")
annotation("javax.ws.rs.Path")
}
此外,注入典型的
@ApplicationScoped
“服务”类是可行的。