Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The @ConfigurationProperties annotation injects null values when decorates a @Bean method in a @Configuration class #19

Open
igarciaes opened this issue Mar 22, 2019 · 4 comments
Labels
type: enhancement New feature or request

Comments

@igarciaes
Copy link

igarciaes commented Mar 22, 2019

Hi,
The ConfigurationProperties annotation injects null values when is used to decorate a Bean method in a Configuration class. I have forked the repository and added an example bean which is configured using the configuration properties annotation. The bean values are populated correctly using only Spring Boot dependencies but the bean configuration properties are populated with null values when Micronaut is used. Here is the commit with the example:
igarciaes@1fb0d4b
I am missing something?
Thanks!

@igarciaes igarciaes changed the title The @ConfigurationProperties annotation inject null values when decorates a @Bean method in a @Configuration class The @ConfigurationProperties annotation injects null values when decorates a @Bean method in a @Configuration class Mar 22, 2019
@graemerocher
Copy link
Contributor

We don't currently support returning @ConfigurationProperties from a @Configuration method. You would need to define the @ConfigurationProperties on the class itself

@igarciaes
Copy link
Author

Ok, thanks @graemerocher for your quick reply.
Then, if is not possible to use the @ConfigurationProperties annotation for bean factory methods in a @Configuration annotated class, could you please describe which would be the code refactoring using Micronaut for cases where the configuration values are injected directly to the bean returned by a factory method:

@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
}

@Bean
@ConfigurationProperties(prefix="spring.secondDatasource")
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
}

We would like to use Micronaut for existing Spring Boot microservices and we would like to estimate the refactoring cost if needed.

Thanks in advance!

@graemerocher
Copy link
Contributor

Since Micronaut does things at compilation time. You have a couple of options.

  1. You can subclass the external class. See https://github.com/micronaut-projects/micronaut-sql/blob/master/jdbc-dbcp/src/main/java/io/micronaut/configuration/jdbc/dbcp/DatasourceConfiguration.java for an example of that
  2. You can use @ConfigurationBuilder to reference an external builder. See https://github.com/micronaut-projects/micronaut-neo4j/blob/master/neo4j-bolt/src/main/java/io/micronaut/configuration/neo4j/bolt/Neo4jBoltConfiguration.java#L60 for an example of that

@igarciaes
Copy link
Author

Thanks @graemerocher for your reply!

@graemerocher graemerocher added type: enhancement New feature or request and removed enhancement labels Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants