1 package com.imooc.bigdata.hos.core; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.util.Properties; 6 7 import org.springframework.core.io.Resource; 8 import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 9 10 /** 11 * Created by jixin on 18-3-8. 12 */ 13 public class HosConfiguration { 14 15 private static HosConfiguration configuration; 16 private static Properties properties; 17 18 static { 19 20 PathMatchingResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver(); 21 configuration = new HosConfiguration(); 22 try { 23 configuration.properties = new Properties(); 24 Resource[] resources = resourceLoader.getResources("classpath:*.properties"); 25 for (Resource resource : resources) { 26 Properties props = new Properties(); 27 InputStream input = resource.getInputStream(); 28 props.load(input); 29 input.close(); 30 configuration.properties.putAll(props); 31 } 32 } catch (IOException e) { 33 e.printStackTrace(); 34 } 35 36 } 37 38 private HosConfiguration() { 39 } 40 41 public static HosConfiguration getConfiguration() { 42 return configuration; 43 } 44 45 46 public String getString(String key) { 47 return properties.getProperty(key); 48 } 49 50 public int getInt(String key) { 51 return Integer.parseInt(properties.getProperty(key)); 52 } 53 54 public boolean getBoolean(String key) { 55 return Boolean.parseBoolean(properties.getProperty(key)); 56 } 57 58 public long getLong(String key) { 59 return Long.parseLong(properties.getProperty(key)); 60 } 61 62 }