0
我正在向@Value
注入一個變量值。出於某種原因,當我有默認值時,它只使用它,它不會在屬性文件中查找它。當我不使用默認值時,它會從屬性文件注入值。沒有其他配置被改變。Spring @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
請看看[這篇文章](https://stackoverflow.com/questions/28369582/spring-boot-spring-always-assigns-default-value-to-property-despite-of-it-bein ),似乎是一個類似的問題。 – juanlumn