7

我想在我的 Kotlin 资源文件中包含一个依赖项。但我不能。

我制作了这个教程:https : //quarkus.io/guides/rest-client-guide 但是,为了开始这个项目,我在我的项目中包含了扩展“kotlin”。

我的代码如下:

国家.kt

package org.acme.restclient

class Country {
  var name:String? = null
  var alpha2Code:String? = null
  var capital:String? = null
  var currencies:List<Currency>? = null
  class Currency {
    var code:String? = null
    var name:String?= null
    var symbol:String? = null
  }
}

国家服务.kt

package org.acme.restclient

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces

@Path("/v2")
@RegisterRestClient
interface CountriesService {
    @GET
    @Path("/name/{name}")
    @Produces("application/json")
    fun getByName(@PathParam("name") name: String): Set<Country>
}

国家资源.kt

package org.acme.restclient

import org.eclipse.microprofile.rest.client.inject.RestClient
import javax.inject.Inject
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Path("/country")
class CountriesResource {
    @Inject
    @RestClient
    lateinit internal var countriesService: CountriesService

    @GET
    @Path("/name/{name}")
    @Produces(MediaType.APPLICATION_JSON)
    fun name(@PathParam("name") name: String): Set<Country> {
        return countriesService.getByName(name)
    }
}

应用程序属性

org.acme.restclient.CountriesService/mp-rest/url=https://restcountries.eu/rest

错误:

12:23:55,340 ERROR [io.qua.dev.DevModeMain] Failed to start quarkus: java.lang.RuntimeException: org.jboss.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.arc.deployment.ArcAnnotationProcessor#build threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.restclient.CountriesService and qualifiers [@Default]
    - java member: org.acme.restclient.CountriesResource#countriesService
    - declared on CLASS bean [types=[org.acme.restclient.CountriesResource, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.restclient.CountriesResource]
    at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:134)
    at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:105)
    at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
Caused by: org.jboss.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkus.arc.deployment.ArcAnnotationProcessor#build threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.restclient.CountriesService and qualifiers [@Default]
    - java member: org.acme.restclient.CountriesResource#countriesService
    - declared on CLASS bean [types=[org.acme.restclient.CountriesResource, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.restclient.CountriesResource]
    at org.jboss.builder.Execution.run(Execution.java:123)
    at org.jboss.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:136)
    at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:110)
    at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:99)
    ... 2 more
Caused by: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.restclient.CountriesService and qualifiers [@Default]
    - java member: org.acme.restclient.CountriesResource#countriesService
    - declared on CLASS bean [types=[org.acme.restclient.CountriesResource, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.restclient.CountriesResource]
    at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:740)
    at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:276)
    at io.quarkus.arc.processor.BeanProcessor.process(BeanProcessor.java:153)
    at io.quarkus.arc.deployment.ArcAnnotationProcessor.build(ArcAnnotationProcessor.java:237)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:506)
    at org.jboss.builder.BuildContext.run(BuildContext.java:413)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1998)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1525)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1416)
    at java.base/java.lang.Thread.run(Thread.java:834)
    at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.acme.restclient.CountriesService and qualifiers [@Default]
    - java member: org.acme.restclient.CountriesResource#countriesService
    - declared on CLASS bean [types=[org.acme.restclient.CountriesResource, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.restclient.CountriesResource]
    at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:326)
    at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:365)
    at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:268)
    ... 14 more

有人可以帮助我吗?

谢谢!

4

1 回答 1

10

这个问题是 Kotlin 处理注释的方式和注释定义中缺少 a 的组合@Target@RestClient

要解决您的问题,只需使用:

   @Inject
   @field: RestClient
   lateinit internal var countriesService: CountriesService
于 2019-04-01T16:05:27.047 回答