我正在为@Value
的变量注入一个值。出于某种原因,当我有默认值时,它只使用它,它不会在属性文件中查找它。当我没有使用默认值时,它会从属性文件中注入值。没有其他配置被更改。
@Value("${migration.paths:#{'classpath:db/migration'}}")
private String dbMigrationPaths;
(我在默认值中使用SPEL,因为它有斜杠)
属性文件配置:
@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;
}
两者都是属性文件,相关属性位于file1
而不是file2
答案 0 :(得分:1)
您的项目中是否有两个属性占位符?如果是,您可能会遇到此处记录的错误:https://jira.spring.io/browse/SPR-9989。最后,请参阅建议的解决方法链接。