(1) 如果引用类加入了spring容器中管理
@Value("${upload.file.localPath}")
private String imagePath;
(2)如果是工具类需要引用:
方法1:// 这儿我的项目路径的resources文件夹下有一个newton.properties的配置文件,这个文件中有个配置名称为switchon.url
ResourceBundle newton = ResourceBundle.getBundle("newton");
String switchOnUrl = newton.getString("switchon.url");
方法2:
Properties properties = new Properties();
resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("newton.properties");
properties.load(resourceAsStream);
String switchOnUrl = properties.getProperty("switchon.url");