@Named doesn't resolve the value parameter

Viewed 156

After upgrading to micronaut 3.x and replacing the annotation Javax.inject to Jakarta.inject. @Named is unable resolve the property.

import io.micronaut.context.annotation.Bean
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Requires
import java.util.concurrent.ExecutorService
import jakarta.inject.Named
import kotlin.coroutines.CoroutineContext

@Factory
open class ExecutorServiceCoroutineContextFactory {

  @Bean
  @Requires(missingBeans = [CoroutineContext::class])
  fun executorServiceCoroutineContext(@Named("\${coroutines.executor}")executorService: ExecutorService): CoroutineContext {
    return ExecutorServiceCoroutineDispatcher(executorService)
  }
}

application.yml

coroutines:
  executor: coroutines

The resulting error


Message: No bean of type [java.util.concurrent.ExecutorService] exists for the given qualifier: @Named('${coroutines.executor}'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Path Taken: new Controller(Client client,CoroutineContext coroutineContext) --> new Controller(Client client,[CoroutineContext coroutineContext]) --> CoroutineContext.executorServiceCoroutineContext([ExecutorService executorService],String name)
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [executorService] of method [executorServiceCoroutineContext] of class: kotlin.coroutines.CoroutineContext

Hardcoding the value "coroutines" does work but wondering why the code can't resolve it.

0 Answers
Related