-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Make @ConfigurationProperties available in conditions #2282
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
Comments
Well, the link is reverse. The |
Is there a chance to respect BTW The another painful scenario is when we create condition and use bean referring
If I access In general with these issues in place, using Do you think that this kind of binding corner cases could be addressed? I (and not only me I guess) will highly appreciate it. |
It's probably going to be pretty hard to make Have you seen the @ConfigurationProperties(prefix = "foo")
@ConditionalOnProperty(prefix="foo", name="bar", matchIfMissing=true)
public class MyConfigurationProperties {
private boolean bar = true;
// getters & setters
} |
Hi Phil, Yes, actually I use
My main concern here is that currently it is counter-intuitive that Can you consider keeping this issue open? I understand that this can be a tricky beast but I believe that it is worth some investigation in the future. Laters! |
Yeah, lets keep this open and take a look when the 1.2 bugs die down. It might be possible to update |
you could also read the metadata at runtime. We're already doing that for the |
Thanks guys. |
Replace @value for @Autowired, as tests fail on the @value sometimes. Probably tied to the following spring boot issue: spring-projects/spring-boot#2282 [#350]
@longfeizheng could you please stop pasting the same comment in several issues? If you have a question, please ask on StackOverflow or join us on Gitter. |
👋 Hi all, Seems I may have just stumbled into this issue as well? Please correct me if I'm mistaken
|
@jamesmehorter You can't safely retrieve beans from the context during condition evaluation as they are called too early in the application context's lifecycle. |
While Just create a custom conditional implementation and use this line.
Here's a gist with full solution. // EDIT: updated the link to gist |
@tokrug The gist does not work any more. Do you still have it somewhere? |
@michaelzangl I have updated the link in the original comment. |
Is this use case being considered to be first-class supported in Spring Boot? Thanks |
@albertocavalcante The issue is open an in the "General Backlog" milestone which means we're still considering it. Having said that, this we have a number of other tasks that are consuming a lot of our bandwidth so we're very unlikely to get to this one anytime soon. |
@philwebb Can you please revisit this and consider this one? |
@rajjaiswalsaumya I'm afraid the comment just above yours still stands. This isn't a particularly high priority compared to the other work we have on. |
In my case I used a @ConfigurationProperties(perfix="test")
data class {
props:Map<String, Any>
}
In the application.properties, I set the properties like this. test.props.foo=...
test.props.bar=... So the |
Hi,
There is a general issue with
@ConfigurationProperties
and beans/classes conditions not working well together. Basically@ConfigurationProperties
properties are instantiated after conditions are evaluated. As a result, conditions can't see those properties.For example creating
@ConfigurationProperties
with some default true value......and using it in
@ConditionalOnProperty("foo.bar")
doesn't evaluate totrue
(becauseOnPropertyCondition#getMatchOutcome
is executed beforeMyConfigurationProperties
is processed by theConfigurationClassPostProcessor
, soPropertyResolver
can't seefoo.bar
property yet).The problem is not limited to
@ConditionalOnProperty
. It affects all conditions that relies on properties or on the other beans referring@ConfigurationProperties
.Fix to that will be highly appreciated :) .
Cheers.
The text was updated successfully, but these errors were encountered: