I've got quite a simple application.yml
file:
spring:
config:
name: android,ios,test,web
I expected to gain an ability to name config files like android.yml
and put them into
classpath:/,classpath:/config/,file:./,file:./config/
as the DEFAULT_SEARCH_LOCATIONS
constant from the ConfigFileApplicationListener
class specifies. I created a file in the same directory with the main config:
android:
clientId: 0
clientSecret: clientSecret
Then I wrote a @Configuration
class with one method to get an instance of ClientDetails
by the @ConfigurationProperties
:
@Configuration
public class TrustedClientInformationConfiguration {
@Bean(name = ANDROID)
@ConfigurationProperties(prefix = ANDROID)
public ClientDetails getAndroidClientDetails() {
return new BaseClientDetails();
}
}
Unfortunately, after autowiring, I got the instance with unfilled fields. What have I missed?
EDIT1: I found and debugged a method where CONFIG_NAME_PROPERTY = "spring.config.name"
is used (it's only one usage), the containsProperty
condition always returns false
:
private Set<String> getSearchNames() {
if (this.environment.containsProperty(CONFIG_NAME_PROPERTY)) {
return asResolvedSet(this.environment.getProperty(CONFIG_NAME_PROPERTY),
null);
}
return asResolvedSet(ConfigFileApplicationListener.this.names, DEFAULT_NAMES);
}
EDIT2: It is a try to create an oauth2 client configuration by moving properties to a separate file for each trusted client. They should be always instantiated despite the active profile.
The spring.config
properties should be set on the command-line as they're needed before any config files are loaded.
However it looks like the feature you actually want is profiles . They're a much easier way to organise different configuration for different environments. Files can be named application-android
, application-test
, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.