会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132474个问题

麻烦老师帮我看下为什么报错。

log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 

### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver 

### The error may exist in com/bjsxt/pojo/mapper/employee2mapper.xml

### The error may involve com.bjsxt.pojo.mapper.employee2mapper.selectall

### The error occurred while executing a query

### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver 

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135)

at com.bjsxt.pojo.dao.impl.employee2impl.selectall(employee2impl.java:22)

at com.bjsxt.pojo.test.Test.main(Test.java:12)

Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver 

at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:244)

at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:223)

at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:219)

at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)

at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:432)

at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)

at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:139)

at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:61)

at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)

at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)

at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)

at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)

... 4 more


Process finished with exit code 1

mybatisdemo.zip


JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 30317楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 30319楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 30321楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 30322楼
Python 全系列/第七阶段:网页编程基础/Ajax 30323楼

老师我在第一个项目里面按照视频里的代码启动Tomcat然后清空控制台访问attr.do的实现效果是这样的


image.png

但是当我在另一个项目里练习的时候发现清空控制台再访问attr.do就是这样的,我什么不是和上面的实现效果一样呢

没有打印出输出语句


image.png


    listener

package com.bjsxt.listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;

/**
 * ServletContext对象属性操作监听器
 */
public class ServletContextAttrListener implements ServletContextAttributeListener {
    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("--------------Added Start----------------");
        System.out.println(scae.getName()+"-----"+scae.getValue());
        System.out.println(scae.getServletContext());
        System.out.println("---------------Added Ended---------------");
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("--------------Removed Start----------------");
        System.out.println(scae.getName()+"-----"+scae.getValue());
        System.out.println(scae.getServletContext());
        System.out.println("---------------Removed Ended---------------");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("--------------Replaced Start----------------");
        System.out.println(scae.getName()+"-----"+scae.getValue());
        System.out.println(scae.getServletContext());
        System.out.println("---------------Replaced Ended---------------");
    }
}


servlet

package com.bjsxt.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/attr.do")
public class ServletContextAttrServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = this.getServletContext();
        //编写触发监听器的三个方法
        servletContext.setAttribute("key","临江仙");
        servletContext.setAttribute("key","ITBZ");
        servletContext.removeAttribute("key");
    }
}


image.png



















JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 30324楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 30325楼
JAVA 全系列/第八阶段:Linux入门到实战/Linux(旧) 30327楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 30329楼
JAVA 全系列/(旧的隐藏)第二十一阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 30330楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637