modified: src/main/java/com/thinker/main/util/BaseProperty.java
new file: src/main/resources/jdbc.properties modified: src/test/java/com/thinker/main/util/BaseTest.java
This commit is contained in:
parent
2e17016f8e
commit
d46b901177
@ -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());
|
||||
// }
|
||||
|
||||
}
|
||||
|
0
src/main/resources/jdbc.properties
Normal file
0
src/main/resources/jdbc.properties
Normal file
@ -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"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user