java代碼讀取properties配置文件實例


簡單的配置文件示例

#接口認證key
apiKey=4fGz356XAjWScx31tRBgePgY6Ma3eQM9i1vj

#平台編碼
sourceCode=CERT2019041

#test接口地址
#用戶
ENDPOINT1=https://api.ifcert.org.cn/p2p/userInfo/test
#散標
ENDPOINT2=https://api.ifcert.org.cn/p2p/scatterInvest/test
#散標狀態
ENDPOINT5=https://api.ifcert.org.cn/p2p/status/test
#還款計划
ENDPOINT10=https://api.ifcert.org.cn/p2p/repayPlan/test
#債權信息
ENDPOINT9=https://api.ifcert.org.cn/p2p/creditor/test
#轉讓項目
ENDPOINT6=https://api.ifcert.org.cn/p2p/transferProject/test
#轉讓狀態
ENDPOINT12=https://api.ifcert.org.cn/p2p/transferStatus/test
#承接信息
ENDPOINT11=https://api.ifcert.org.cn/p2p/underTake/test
#交易流水
ENDPOINT4=https://api.ifcert.org.cn/p2p/transact/test
#產品信息
ENDPOINT13=https://api.ifcert.org.cn/p2p/lendProduct/test
#產品配置
ENDPOINT14=https://api.ifcert.org.cn/p2p/lendProductConfig/test
#投資明細
ENDPOINT15=https://api.ifcert.org.cn/p2p/lendParticulars/test

代碼示例

    @RequestMapping(value = "register", method = RequestMethod.GET)
    @AvoidDuplicateSubmission(needSaveToken = true)
    public ModelAndView register(String referrer) {
        Properties props = new Properties();
        try {
            props.load(Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream("config/dataaccess/access.properties"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException("找不到配置chinapnr.properties文件", e);
        } catch (IOException e) {
            throw new RuntimeException("讀取配置chinapnr.properties文件出錯", e);
        }
        String a = props.getProperty("apiKey");
        String b = props.getProperty("sourceCode");
        String c = props.getProperty("ENDPOINT1");


        System.out.println(a+";"+b+";"+c);
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM