请问以下大佬们getResourceAsStream返回为null的问题
我写的一个JDBCUtils工具类,在idea上能正常跑,但在eclipsegetResourceAsStream返回就为null了。路径没有问题我可以读出properties文件内容。路径前面也加过/也不行。所以求问哈论坛的大佬们这是为啥啊public class JDBCUtils {
private static DataSource DATA_SOURCE;
static{
Properties pro = new Properties();
//ClassLoader classLoader = JDBCUtils.class.getClassLoader();
InputStream in = JDBCUtils.class.getClassLoader().getResourceAsStream("src/main/resources/db.properties");
try {
pro.load(in);
DATA_SOURCE = DruidDataSourceFactory.createDataSource(pro);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
Connection conn = null;
try {
conn = DATA_SOURCE.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void close(Connection conn, Statement st){
if(st != null){
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close(Connection conn, Statement st, ResultSet rs){
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(st != null){
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}