为了使spring评估占位符,您需要在使用类时使用
PropertySourcesPlaceholderConfigurer静态
@Bean方法注册
Bean
@Configuration,如下所示:
@Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {return new PropertySourcesPlaceholderConfigurer();}根据JavaDoc:
PlaceholderConfigurerSupport的特殊化,可针对当前的Spring
Environment及其PropertySources解析bean定义属性值和@Value注释中的$ {…}占位符。



