Ошибка при внедрении некоторой зависимости с kotlin + quarkus

Я хочу включить зависимость в свой файл ресурсов Kotlin. Но я не могу.

Я сделал это руководство: https://quarkus.io/guides/rest-client-guide Но, чтобы начать проект, я включил в свой проект расширение «kotlin».

Мои коды ниже:

Country.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
  }
}

CountryService.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>
}

CountryResource.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)
    }
}

application.properties

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

Кто-нибудь может мне помочь?

Спасибо!


person Renan Vaz    schedule 01.04.2019    source источник
comment
Будущие читатели могут захотеть проверить это: stackoverflow.com/questions/55513502/ и это: byteslounge.com/tutorials /   -  person granadaCoder    schedule 22.10.2019


Ответы (1)


Эта проблема возникает в результате сочетания того, как Kotlin обрабатывает аннотации, и отсутствия символа a @Target в определении аннотации @RestClient.

Чтобы решить вашу проблему, просто используйте:

   @Inject
   @field: RestClient
   lateinit internal var countriesService: CountriesService
person geoand    schedule 01.04.2019
comment
Рад это слышать!. Пожалуйста, примите ответ, чтобы будущие читатели сразу знали, что это правильное решение, без необходимости читать комментарии, спасибо :) - person geoand; 02.04.2019