无法在Quarkus kotlin应用程序中注入REST客户端界面

问题描述 投票:0回答:1

我试图为我的quarkus-rest-client添加一个post-service示例,这是一个用Quarkus构建的简单REST API。

Java版本运行良好。

[当我添加另一个Kotlin来测试Quarkus中对kotlin和Gradle的支持时,它失败了,无法将REST Client接口作为CDI bean注入。

[PostControlloer是Jaxrs资源,公开了结合了原始两个API的聚合API。

@Path("/api")
@RequestScoped
class PostController(@Inject @RestClient val client: PostResourceClient) {

//    @Inject
//    @RestClient
//    lateinit var client: PostServiceClient

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun getPosts(@QueryParam("q")
                 q: String,
                 @QueryParam("offset")
                 @DefaultValue("0")
                 offset: Int,
                 @QueryParam("limit")
                 @DefaultValue("10")
                 limit: Int): Response {
        val posts = this.client.getAllPosts(q, offset, limit).entity as List<Post>
        val count = this.client.countAllPosts(q).entity as Long
        return ok(PostPage(posts, count)).build()
    }

}

以上两种注入Bean的方法均失败。

REST客户端界面:

@Path("/posts")
@RegisterRestClient
interface PostResourceClient {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun getAllPosts(
            @QueryParam("q")
            q: String,
            @QueryParam("offset")
            @DefaultValue("0")
            offset: Int,
            @QueryParam("limit")
            @DefaultValue("10")
            limit: Int
    ): Response

    @GET
    @Path("count")
    @Produces(MediaType.APPLICATION_JSON)
    fun countAllPosts(
            @QueryParam("q")
            q: String
    ): Response

}

此Rest Client界面的应用程序配置。

com.example.PostResourceClient/mp-rest/url=http://localhost:8080
com.example.PostResourceClient/mp-rest/scope=javax.inject.Singleton

完整的代码是here

kotlin resteasy jsonb quarkus microprofile
1个回答
1
投票

Error to inject some dependency with kotlin + quarkus重复,这是MicroProfile RestClient问题。请参阅原始SO答案中的解决方法。

MicroProfile RestClient上已经打开一个问题来解决此问题,并在Quarkus问题跟踪器中进行了跟踪:https://github.com/quarkusio/quarkus/issues/5413

© www.soinside.com 2019 - 2024. All rights reserved.