Skip to content

Support ConfigurationProperties property injection in constructors #1602

Closed
@rgilles

Description

@rgilles

Thanks for reporting an issue for Micronaut, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. clone the following repository: https://github.com/rgilles/mn-data-class-config.git
  2. run mvn test
  3. see the test in error

Bis

  1. create a Kotlin data class annotated with @ConfigurationProperties
  2. Inject the dataclass in the application or a test
  3. you get the following error:
io.micronaut.context.exceptions.DependencyInjectionException: 
Failed to inject value for parameter [name] of class: mn.dataclass.config.MyConfig

Message: No bean of type [java.lang.String] exists. Ensure the class is declared a bean and if you are using Java or Kotlin make sure you have enabled annotation processing.
Path Taken: MyConfigTest.config --> new MyConfig([String name])
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [java.lang.String] exists. Ensure the class is declared a bean and if you are using Java or Kotlin make sure you have enabled annotation processing.

Workaround:
Mix Java and Kotlin in the project and do the same thing but use Java POJO instead of Kotlin data class for the @ConfigurationProperties then it will works.

Expected Behaviour

@ConfigurationProperties should work with Kotlin data class as it works with Java POJO

Actual Behaviour

If you use @ConfigurationProperties on a Kotlin data class an exception is throw at runtime

Environment Information

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Example Application

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions