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
Using @ConfigurationProperties methods in @Requires annotation #6173
Using @ConfigurationProperties methods in @Requires annotation #6173
Conversation
Micronaut doesn't use reflection, to avoid that you would need to have the method I would suggest using |
I guess the only advantage of this approach that could be is if some kind of compilation time checking is supported, but even then I don't think it should support methods but only properties. Something like:
And if
But there is lots of think about (what about nested properties "foo.bar", what about when |
@graemerocher Since the original issue was about avoiding duplication, I would also suggest usage of
then we could do something like:
instead of
The problem of this approach is handling default values of properties specified inside
In this case I would expect the conditional bean to be created even if I don't explicitly specify the property in external configuration since the default value is already provided inside the class. The same problem arises if I want the configuration property value to equal/not equal certain value:
The only solution I can see is using bean introspection for all |
Yes I think it would have to refer to the non-normalized name of properties only like |
@graemerocher |
@GavrilovSV will do, I think it needs some consideration as it will essentially generate introspections for all configuration properties right? This could have memory implications |
@dstepanov what do you think? A lot of work has gone into this PR (Thanks!) perhaps there is a way to generate an optimized resolution handle to get the value of the property without an introspection or perhaps generate an introspection only if needed |
Yes, this implementation generates introspections for all configuration properties, even when those classes are not referenced in @requires anywhere. On the other hand it seems to me like the main advantage of configuration properties is validation support, which requires introspections anyway. But if a way to generate introspections only when needed (or avoiding them at all) could be proposed, that would be great |
Looks good, I think this should also support checking if the configuration is implementing |
inject/src/main/java/io/micronaut/context/RequiresCondition.java
Outdated
Show resolved
Hide resolved
We can log warning on compilation if
If introspection for config properties class can not be loaded, the conditional bean referencing it will not be loaded as well |
The idea behind
This will be confusing. I would prefer an exception if the property cannot be accessed because of the missing introspection. |
Also I am unsure we should be generating introspections for all configuration properties. A user can always use |
@dstepanov
@graemerocher |
|
@graemerocher @dstepanov |
Given there isn't anything in this feature that actually requires Edit: I suppose the above example could be a breaking change if people are using the annotation incorrectly. Perhaps add a |
One issue that we have to be careful about is that currently If we isolate it to just configuration properties maybe those can be mitigated somewhat but I am not super keen on adding bean initialization to the |
We should be able to put together the property string from the annotations and convert it to a property check |
What about |
The current implementation is in fact already doing that And since the resolution context is not passed it is likely to cause issues |
cb0b263
to
d86bc39
Compare
d86bc39
to
a6f28d6
Compare
inject/src/main/java/io/micronaut/inject/writer/BeanDefinitionWriter.java
Outdated
Show resolved
Hide resolved
70780ab
to
9869ddb
Compare
@graemerocher @jameskleeh |
d5c5a7b
to
e4449cf
Compare
e4449cf
to
4de2b14
Compare
@graemerocher |
Thanks for the contribution! |
This is a possible solution to resolve #5350
I'd like someone to review this PR to find out whether this solution is ok, or some sort of fail fast validation is expected in case of mistyping the method name or providing method with wrong return type. Then I can proceed with the implementation of similar functionality in other annotations like @scheduled etc