如果尝试使用
@Value("")注释访问属性值,则应声明PropertySourcesPlaceholderConfigurerBean。
尝试在配置类中添加以下代码段。
@Beanpublic static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer();}如果不想声明它,请尝试在
org.springframework.core.env.Environment类中自动装配它,以获取属性值。
@Autowiredprivate Environment environment;public void readValues() { System.out.println("Some Message:" + environment.getProperty("<Property Name>"));}


