Reputation: 1262
I am injecting a value to a variable with @Value
. For some reason, when I have the default value, it only uses it, it doesn't look for it in the properties file. When I'm not using the default value, it does inject the value from the properties file. No other configurations were changed.
@Value("${migration.paths:#{'classpath:db/migration'}}")
private String dbMigrationPaths;
(I'm using SPEL in the default value because it has slashes)
The property file configuration:
@Bean
public static PropertySourcesPlaceholderConfigurer configDataSourcesPropertyFile() {
PropertySourcesPlaceholderConfigurer bean = new PropertySourcesPlaceholderConfigurer();
bean.setLocations(new ClassPathResource[]{
new ClassPathResource("/file1"),
new ClassPathResource("/file2")
});
bean.setIgnoreUnresolvablePlaceholders(true);
bean.setIgnoreResourceNotFound(true);
return bean;
}
Both are properties files, and the property in question resides in file1
and not in file2
Upvotes: 1
Views: 1030
Reputation: 74
Do you have two property placeholders in your project? If yes, you may be running into this bug documented here: https://jira.spring.io/browse/SPR-9989. See at the end there is a link to suggested workaround.
Upvotes: 2