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
使用MyBatis工具類openSession()方法,junit通過,在tomcat執行報錯
慕后端2248651
2019-11-02 13:39:55