package org.springframework.beans;
import java.util.Properties;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class StudentTest {
@Test
public void getProperties()throws Exception{
//资源文件位置,resources目录下
String path = "student.properties";
//方法一:
Properties p1 = PropertiesLoaderUtils.loadAllProperties(path);
Object name = p1.get("name");
//方式二
Resource resource = new ClassPathResource(path);
Properties p2 = PropertiesLoaderUtils.loadProperties(resource);
Object object = p2.get("name");
}
}