猿问

mybatis Configuration.xml 无法读取到 / 我设置成绝对路径也无法读取 希望老师解决下

public class DBAccess {

public SqlSession getSqlSession() throws IOException {

// 通过配置文件获取数据库连接信息

Reader reader = Resources.getResourceAsReader("C:\\Users\\leon\\workspace\\mybatis_one\\config\\Configuration.xml");

// 通过配置信息构建一个SqlSessionFactory

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

// 通过sqlSessionFactory打开一个数据库会话

SqlSession sqlSession = sqlSessionFactory.openSession();

return sqlSession;

}

}


public class Inport {

public static void main(String[] args) {

UserService userService = new UserService();

List<User> users = userService.queryAllUserList();

System.out.println(users);

}

}


Exception

java.io.IOException: Could not find resource C:\Users\leon\workspace\mybatis_one\config\Configuration.xml

at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:110)

at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:97)

at org.apache.ibatis.io.Resources.getResourceAsReader(Resources.java:155)

at com.leon.db.DBAccess.getSqlSession(DBAccess.java:17)

at com.leon.dao.UserDao.queryAllUserList(UserDao.java:48)

at com.leon.service.UserService.queryAllUserList(UserService.java:21)

at com.leon.service.Inport.main(Inport.java:10)

[]





qpqpwj
浏览 1303回答 1
1回答

qpqpwj

已解决 这是我的项目目录结构 C:\Users\leon\workspace\mybatis_one\src\main\java\com\leon\dao只要放到java这一层的目录下面就可以了
随时随地看视频慕课网APP

相关分类

Java
我要回答