问题描述
在Action中,当我要向数据库中插入一条记录时,报了下面的错误:javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/ibatis/io/Resourcesorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:294)org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)com.zrxx.action.ProjectAction.execute(ProjectAction.java:33)org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)javax.servlet.http.HttpServlet.service(HttpServlet.java:637)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)java.lang.NoClassDefFoundError: org/apache/ibatis/io/Resourcescom.zrxx.util.SqlSessionFactoryTool.getSqlSessionFactory(SqlSessionFactoryTool.java:30)com.zrxx.dao.BaseDao.openSession(BaseDao.java:15)com.zrxx.dao.BaseDao.openSession(BaseDao.java:10)com.zrxx.dao.ProjectDao.insertPro(ProjectDao.java:13)com.zrxx.action.ProjectAction.add(ProjectAction.java:54)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invoke(Method.java:597)org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)com.zrxx.action.ProjectAction.execute(ProjectAction.java:33)org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)javax.servlet.http.HttpServlet.service(HttpServlet.java:637)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)这个错误是当dao对象已经创建了,调用dao.insert()时发出的附上我的SqlSessionFactoryTool源代码:public class SqlSessionFactoryTool {private static SqlSessionFactoryTool tool;private SqlSessionFactory factory;public static SqlSessionFactoryTool getInstance(){if(tool == null)tool = new SqlSessionFactoryTool();return tool;}public SqlSessionFactory getSqlSessionFactory(){String resource = "/mybatis.xml";Reader reader = null;try {reader = Resources.getResourceAsReader(resource);} catch (IOException e) {e.printStackTrace();}factory = new SqlSessionFactoryBuilder().build(reader);return factory;}这是我的目录结构 问题补充:Wind_ZhongGang 写道
解决方案
org/apache/ibatis/io/Resources 是Ibatis核心包的类,明显你没有把ibatis核心包加入运行的classpath:/WEB-INF/lib/下
解决方案二:
ibatis相关包导入不全,看看你的lib下的ibatis包有哪些?