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

我试图为我的post-service添加一个quarkus-rest-client示例,这是一个用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

watarase 回答:REST客户端界面无法注入Quarkus kotlin应用程序

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

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

本文链接:https://www.f2er.com/3015326.html

大家都在问