我试图为我的post-service添加一个quarkus-rest-client示例,这是一个用Quarkus构建的简单REST API。
java版本运行良好。
当我添加另一个Kotlin来测试Quarkus中的kotlin和Gradle支持时,它失败了,REST客户端接口不能作为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客户端接口的应用程序配置。
com.example.PostResourceClient/mp-rest/url=http://localhost:8080
com.example.PostResourceClient/mp-rest/scope=javax.inject.Singleton完整的代码是here。
发布于 2019-11-28 19:33:47
与Error to inject some dependency with kotlin + quarkus相同,这是一个MicroProfile RestClient问题。请参阅原始SO答案中的解决方法。
已经在Quarkus RestClient上打开了一个问题以修复此问题,并在Quarkus问题跟踪程序上进行了跟踪:https://github.com/quarkusio/quarkus/issues/5413
https://stackoverflow.com/questions/59086151
复制相似问题