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
@ConfigurationProperties locations #6726
Comments
We want to promote the use of a consistent If, for some reasons, you want to have that configuration separate in custom files, you can use the We don't think that having one bean tied to one source file is a good thing. There's some nice content in this comment as well: #6220 (comment) |
This is very inconvenient, since configuration like white-lists can be very long and adding keys feels like "polluting" config file. I guess PropertiesConfigurationFactory with YamlPropertiesFactoryBean will do the trick in that case. |
I have one single class that loads its data from an external yaml file, unrelated to the application environment. What exactly am I supposed to replace this with, without polluting the global environment or exposing the implementation requirements of this class? |
This issue is closed and I think I already replied to that question. If that's not enough, please ask on stackoverflow. |
@OrangeDog how do you solved? |
That's how I fixed it: public class YamlPropertySourceFactory implements PropertySourceFactory {
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
return name != null ? new PropertySourcesLoader().load(resource.getResource(), name, null) : new PropertySourcesLoader().load(
resource.getResource(), getNameForResource(resource.getResource()), null);
}
private static String getNameForResource(Resource resource) {
String name = resource.getDescription();
if (!StringUtils.hasText(name)) {
name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
}
return name;
}
} Mark your properties class: @PropertySource(value` = "classpath:someyml.yml", factory = YamlPropertySourceFactory.class)
@ConfigurationProperties("prefix") That's to make load YML at all. Since spring boot 1.5.4 it doesn't work at all. |
@Zubastick I want to get the array through @value,But they never get it |
I still don't get this...Why using locations in configurationproperties is bad? It took me so much time to find an alternative solution... |
I get the desire to reduce code smell and advocate for a clean environment, but few of us work in such nice environments, and often we don't get to choose how our configurations are handed to us. I really hope Spring brings it back in a future release! |
Question
Hey,
Before Spring Boot 1.4 I've been using
@ConfigurationProperties
to configure simmilar beans with different properties.Example:
Now, not only this code does not compile, since prefix is duplicated, but also
locations
param is deprecated.So is there any way to achieve similar result but without using prefixes? I just want to have very similar configuration files to configure multiple beans.
The text was updated successfully, but these errors were encountered: