junit没问题 @Test public void testGetList(){ SqlSession sqlSession=null; List<User> list=new ArrayList<User>(); try{ sqlSession=MyBatisUtil.openSession(); list=sqlSession.selectList("demo.selectList"); System.out.println(list); }catch (Exception e){ e.printStackTrace(); }finally { MyBatisUtil.closeSession(sqlSession); } System.out.println(list); } tomcat执行报错 public List<User> getList() { SqlSession sqlSession=null; List<User> list=new ArrayList<User>(); try{ sqlSession=MyBatisUtil.openSession(); list=sqlSession.selectList("demo.selectList"); System.out.println(list); }catch (Exception e){ e.printStackTrace(); }finally { MyBatisUtil.closeSession(sqlSession); } return list; } HTTP Status 500 – Internal Server Error Type 异常报告 消息 Servlet execution threw an exception 描述 服务器遇到一个意外的情况,阻止它完成请求。 Exception javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) Root Cause java.lang.NoClassDefFoundError: Could not initialize class com.imooc.util.MyBatisUtil com.imooc.dao.UserDao.getList(UserDao.java:55) com.imooc.servlet.MainServlet.doGet(MainServlet.java:23) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) Note 主要问题的全部 stack 信息可以在 server logs 里查看 Apache Tomcat/8.5.46
慕慕5436299
慕设计2395807
慕妹4267064