-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Conditional registration of @ConfigurationProperties bean #2312
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
This is tangentially related to #2282. |
Can't you do this: @Bean
@ConfigurationProperties('my.service')
@ConditionalOnWhatever
public ServiceProps serviceProps() { return new ServiceProps(); } |
The issue is specifically that |
I'm not sure I understand the use case yet. We often use a single "enabled" flag to switch a feature on. Is that the sort of thing? |
Sort of, except that if the properties are present, I don't understand the purpose of a separate |
I think that #2282 is a better take at this issue. If I understand what you're saying, the The other problem is when you want to disable the auto-config. Let's assume that you have configured tons of properties for that POJO. With your system, you'll have to comment these out instead of just adding a My point is that the separate |
I can see the multiple-properties-merge issue, and looking at the What about a
(I think that #2282 and this one are both distinct flawed approaches at the same general goal, which seems to be something like this.) |
I am sorry, I didn't get your example. |
I mean an |
Oh, interesting. |
@Configuration
@EnableConfigurationProperties(ServiceProps .class)
public class CoreConfig {
} |
We're cleaning out the issue tracker and closing issues that we've not seen much demand to fix. Feel free to comment with additional justifications if you feel that this one should not have been closed. |
This looks intended to tag as "declined" based on the @philwebb 's comment. |
Thanks @izeye. I've changed the tag. |
For anyone interested in a flexible workaround check my comment in another issue. It's a full implementation of |
I have an outstanding SO question that I don't think is supported as a use case as of 1.2.1. Essentially, I would like to use the functionality provided by
@ConditionalOnProperty
along with the type-safe@ConfigurationProperties
. Currently, Spring Boot registers the properties bean regardless of whether any of the properties listed on it exist, so it's impossible to use@ConditionalOnBean(MyConfigProps.class)
(I just get a bean with allnull
fields).I would like either a way to suppress registration of an "empty" properties bean or a condition that matches only if the bean of the specified
@ConfigurationProperties
class exists.Example:
The text was updated successfully, but these errors were encountered: