diff --git a/src/main/java/com/thinker/main/util/BaseProperty.java b/src/main/java/com/thinker/main/util/BaseProperty.java index 410b866..10ae140 100644 --- a/src/main/java/com/thinker/main/util/BaseProperty.java +++ b/src/main/java/com/thinker/main/util/BaseProperty.java @@ -2,12 +2,12 @@ package com.thinker.main.util; import org.apache.log4j.Logger; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Properties; /** * Created by lzh on 16-6-13. + * 用于加载配置文件 */ public class BaseProperty { private static Properties prop; @@ -15,8 +15,15 @@ public class BaseProperty { private static Logger log = Logger.getLogger(BaseProperty.class); static { prop = new Properties(); - log.info("加载配置文件"); - in = BaseProperty.class.getResourceAsStream(BaseProperty.class.getResource("/").getPath()+"/mybatis.properties"); +// log.info("加载配置文件"); + try { + in = new BufferedInputStream(new FileInputStream( + BaseProperty.class.getResource("/").getPath()+"/mybatis.properties")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } +// in = BaseProperty.class.getResourceAsStream("/mybatis.properties"); + System.out.println(BaseProperty.class.getResource("/").getPath()+"/mybatis.properties"); try { prop.load(in); } catch (IOException e) { @@ -29,17 +36,10 @@ public class BaseProperty { } } } - - public static String getMapping(){ - return prop.getProperty("mapping").trim(); + public static String getValue(String name){ + return prop.getProperty(name); } - - public static String getMapper(){ - return prop.getProperty("mapper").trim(); + public static void main(String[] args) { + System.out.println(BaseProperty.getValue("mapper")); } - -// public static void main(String[] args) { -// System.out.println(BaseProperty.getMapper()); -// } - } diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/thinker/main/util/BaseTest.java b/src/test/java/com/thinker/main/util/BaseTest.java index 8db5cf4..482b83c 100644 --- a/src/test/java/com/thinker/main/util/BaseTest.java +++ b/src/test/java/com/thinker/main/util/BaseTest.java @@ -5,6 +5,6 @@ package com.thinker.main.util; */ public class BaseTest { public static void main(String[] args) { - System.out.println(BaseProperty.getMapper()); + System.out.println(BaseProperty.getValue("mapper")); } }