spring框架使用properties或yml配置信息

1,按格式在properties或yml文件中保存信息

2,将配置文件读入到bean,(注意:在哪个上下文环境装配,spring context还是在springmvc context)

@Bean

public PropertyPlaceholderConfigurer propertyConfigurer(){
PropertyPlaceholderConfigurer property=new PropertyPlaceholderConfigurer();
property.setLocation(new ClassPathResource("jdbc.properties"));
property.setFileEncoding("utf-8");
return property;

}

3,在对应的spring context或 mvc context 上下文环境使用@value注入,static属性使用setter方法注入

猜你喜欢

转载自blog.csdn.net/swordmanchen/article/details/79771560