mybatis与struts1 [java.lang.NoClassDefFoundError:org/apache/ibatis/io/Resources]

在Action中,当我要向数据库中插入一条记录时,报了下面的错误:
[code="java"]
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/ibatis/io/Resources
org.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/Resources
com.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)
[/code]
这个错误是当dao对象已经创建了,调用dao.insert()时发出的
附上我的SqlSessionFactoryTool源代码:
[code="java"]
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;
}

[/code]
这是我的目录结构

[img]http://dl.iteye.com/upload/attachment/597707/8f659481-6204-34e4-9c24-18ba93290695.png[/img]

2个回答

org/apache/ibatis/io/Resources 是Ibatis核心包的类,明显你没有把ibatis核心包加入运行的classpath:/WEB-INF/lib/下

ibatis相关包导入不全,看看你的lib下的ibatis包有哪些?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐