您的位置:首页 > 编程语言 > Java开发

Spring-读取properties文件

2016-09-12 17:58 225 查看
文件的名字以及格式

hh.properties

aaa=提莫队长正在送命

方法1:
spring.xml中schema要这样写
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd" 
然后公共配置要这样写
<!-- 读取properties文件-->
<util:properties id="properties" location="classpath:hh.properties"/>
然后java类中要
@Autowired
private Properties properties;
方法中要这样写
public void m1(){
//这样就会输出提莫队长正在送命
System.out.println(properties.getProperty("aaa"));
}
方法2:
Properties properties = new Properties();
File f=ResourceUtils.getFile("classpath:hh.properties");
properties.load(new InputStreamReader(new FileInputStream(config), "utf-8"));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring