• spring下配置tomcat jdbc pool 报找不到“com.mysql.jdbc.Driver“类


    初始配置

     1 
     2     
     3         
     4             
     5                 
     6                 
     7                 
     8                 
     9                 
    10                 
    11                 
    12                 
    13                 
    14                 
    15                 
    16                 
    17                 
    18                 
    19                 
    20                 
    21                 
    22                 
    23                 
    24                 
    25                 
    26             
    27         
    28     
    29 
    30 
    31     
    32     
    34         
    35         
    36         
    37             
    38                 
    39                 
    40                 
    41                 
    42             
    43         
    44         
    45         
    46             
    47                 org.hibernate.cfg.ImprovedNamingStrategy
    48                 org.hibernate.dialect.MySQL5Dialect
    49                 com.mysql.jdbc.Driver
    50                 ${database.url}
    51                 ${database.username}
    52                 ${database.password}
    53                 3
    54                 18
    55                 10
    56                 update
    57                 true
    58                 true
    59                 none
    60             
    61         
    62     

    启动时报错, 

     1 ...
     2 
     3 java.sql.SQLException: com.mysql.jdbc.Driver
     4     at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254) ~[tomcat-jdbc.jar:na]
     5     at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182) ~[tomcat-jdbc.jar:na]
     6     at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:702) ~[tomcat-jdbc.jar:na]
     7     at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:634) ~[tomcat-jdbc.jar:na]
     8     at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:488) ~[tomcat-jdbc.jar:na]
     9     at org.apache.tomcat.jdbc.pool.ConnectionPool.(ConnectionPool.java:144) ~[tomcat-jdbc.jar:na]
    10 
    11 ...
    12 
    13 at javax.management.remote.rmi.RMIConnectionImpl.access$300(Unknown Source) [na:1.8.0]
    14     at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source) [na:1.8.0]
    15     at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source) [na:1.8.0]
    16     at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source) [na:1.8.0]
    17     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:201402101544]
    18     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:201402101544]
    19     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:201402101544]
    20     at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0]
    21     at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) [na:1.8.0]
    22     at sun.rmi.transport.Transport$1.run(Unknown Source) [na:1.8.0]
    23     at sun.rmi.transport.Transport$1.run(Unknown Source) [na:1.8.0]
    24     at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0]
    25     at sun.rmi.transport.Transport.serviceCall(Unknown Source) [na:1.8.0]
    26     at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) [na:1.8.0]
    27     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) [na:1.8.0]
    28     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) [na:1.8.0]
    29     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0]
    30     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0]
    31     at java.lang.Thread.run(Unknown Source) [na:1.8.0]
    32 Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    33     at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0]
    34     at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0]
    35     at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0]
    36     at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0]
    37     at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0]
    38     at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0]

    这篇文章解释了原因 http://stackoverflow.com/questions/4790589/sqlexception-w-tomcat-7-0-jdbc-connection-pool-and-mysql , 大概意思是加载 数据库连接驱动jar包(tomcat?) 和 tomcat jdbc包(spring?) 不是同一个Classloader, 所以需要改为如下配置

     1 
     2     
     3         
     4         
     5         
     6         
     7     
     8 
     9     
    10     
    11         
    12         
    13         
    14         
    15         
    16         
    17         
    18         
    19         
    20         
    21         
    22         
    23         
    24         
    25         
    26         
    27         
    28         
    29         
    30         
    31     

     其他配置不变

  • 相关阅读:
    「torch.cosine_smilarity() = 0」引发的关于cpu与gpu精度问题的探讨
    公交调度-车次链编制贪心算法
    别再用Excel了!用帆软报表做营收报表效率高十倍!
    centos 6升级内核小版本以及更新yum源
    VSCode 使用CMakePreset找不到cl.exe编译器的问题
    使用kalibr标定工具进行单目相机和双目相机的标定
    centos8安装jenkins,gitee+webHook配置
    【BOOST C++ 15 泛型编程】(3)Boost.Fusion
    STM32智能仓储管理系统教程
    插入排序算法
  • 原文地址:https://blog.csdn.net/liuliuhelingdao/article/details/126882873