网上找了很多,都是说加classpath* , 然而加了依然报错:
Could not open ServletContext resource [/classpath*:xx.properties]
最后换成classth: 仍然报错:
Could not resolve placeholder 'x1' in string value "${x1}"
最后把@value("${x1}") 这个原因是项目中有多个PropertyPlaceholderConfigurer相关的配置。如xml 中配置了
在加上@PropertySource ,就是两个地方配置了。需要给propertyConfigurer 这个bean 加上
正确写法:
@Configuration
@PropertySource("classpath:xxx.properties") //此处不是 classpath*:
public class ParamConfig {
@Value("x1") //此处不要用 ${}
private String x1;
public String getX1(){
return x1;
}
//使用${} 必须加这个
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}