Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin @注入不在Quarkus上工作+;Vertx+;科特林_Kotlin_Vert.x_Quarkus - Fatal编程技术网

Kotlin @注入不在Quarkus上工作+;Vertx+;科特林

Kotlin @注入不在Quarkus上工作+;Vertx+;科特林,kotlin,vert.x,quarkus,Kotlin,Vert.x,Quarkus,我正在尝试使用Quarkus和Kotlin编写一个简单的反应式应用程序,其中只有一个端点,并使用Vertx。但这段简单的代码不起作用: package com.acme import io.quarkus.vertx.web.Route import io.vertx.core.Vertx import io.vertx.core.http.HttpMethod import io.vertx.ext.web.RoutingContext import javax.enterprise.con

我正在尝试使用Quarkus和Kotlin编写一个简单的反应式应用程序,其中只有一个端点,并使用Vertx。但这段简单的代码不起作用:

package com.acme

import io.quarkus.vertx.web.Route
import io.vertx.core.Vertx
import io.vertx.core.http.HttpMethod
import io.vertx.ext.web.RoutingContext
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject

@ApplicationScoped
open class Routing {

    @Inject
    lateinit var vertx: Vertx

    @Route(path = "/hello", methods = [HttpMethod.GET])
    fun handle(rc: RoutingContext) {
        println(vertx)
        rc.response().end("hello")
    }
}
我得到一个例外:

kotlin.UninitializedPropertyAccessException: lateinit property vertx has not been initialized
        at com.acme.Routing.handle(Routing.kt:18)
我已经阅读了关于Kotlin的Quarkus文档(它仍然是一种预览技术),并介绍了有关使用“@field:xxx”的内容,但我尝试了很多方法,但都没有成功。如果有人知道答案,我们将不胜感激


我在Java中也尝试过同样的方法,效果非常好@Inject Vertx或@Inject EventBus,但在Kotlin中似乎不可能

我以您的示例类为例,它运行良好:

(只需在项目文件夹中执行
/gradlew quarkusDev
。)

您是否使用Quarkus项目创建者设置了项目

检查“EclipseVert.x”、“EclipseVert.x-Web”和“Kotlin”(添加底部)

然后,类路径上应该有以下依赖项(渐变表示法): -org.jetbrains.kotlin:kotlin-stdlib-jdk8 -io.quarkus:quarkus kotlin -io.quarkus:quarkus顶点
-io.quarkus:quarkus Vertex web

我使用了您的示例类,它运行良好:

(只需在项目文件夹中执行
/gradlew quarkusDev
。)

您是否使用Quarkus项目创建者设置了项目

检查“EclipseVert.x”、“EclipseVert.x-Web”和“Kotlin”(添加底部)

然后,类路径上应该有以下依赖项(渐变表示法): -org.jetbrains.kotlin:kotlin-stdlib-jdk8 -io.quarkus:quarkus kotlin -io.quarkus:quarkus顶点 -io.quarkus:quarkus Vertex web

根据需要,应添加
@field:Default
“以处理Kotlin反射注释定义上缺少@Target的问题”:

根据需要,应添加
@field:Default
“以处理Kotlin反射注释定义中缺少@Target的问题”:


是的,你的,很好用。我看到的唯一区别是我使用的是Maven。在这里你可以看到:。是的,我用Quarkus生成器生成了它,所以我没有在pom.xmlNo中更改任何内容。正如您在Github中所做的那样,通过与Gradle的对话解决了问题。很奇怪,是的,你的,很好用。我看到的唯一区别是我使用的是Maven。在这里你可以看到:。是的,我用Quarkus生成器生成了它,所以我没有在pom.xmlNo中更改任何内容。正如您在Github中所做的那样,通过与Gradle的对话解决了问题。很奇怪
    @Inject
    @field: Default
    lateinit var vertx: Vertx