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); }}Exceptionjava.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)[]
1 回答
qpqpwj
TA贡献1条经验 获得超0个赞
已解决
这是我的项目目录结构
C:\Users\leon\workspace\mybatis_one\src\main\java\com\leon\dao
只要放到java这一层的目录下面就可以了
添加回答
举报
0/150
提交
取消