1. 程式人生 > >java web專案中的properties檔案中的屬性值在啟動後進行修改(資料庫密碼加密等)

java web專案中的properties檔案中的屬性值在啟動後進行修改(資料庫密碼加密等)

public class DecryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    private Resource[] locations;

    public void setLocations(Resource[] locations) {
        this.locations = locations;
    }

    public void loadProperties(Properties props) throws IOException {
        if (this.locations != null) {
            for(Resource location : locations){
                props.load(location.getInputStream());
            }
            props.put("name", "Kevin-change");
        }
    }
}

現使用: