spring讀取properties文件的兩種方式

//第一種this

    Properties prop = new Properties();  spa

    prop.load(new ClassPathResource("config/file.properties").getInputStream());ip

//第二種get

    Properties prop = new Properties();    file

    prop.load(this.getClass().getClassLoader().getResourceAsStream("ipConfig.properties"));co

  // 根據 key 獲取 value
   value = prop.getProperty("key");
config

相關文章
相關標籤/搜索