初始配置
1 23 29 30 31 324 285 276 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 34 35 36 37 4438 4339 40 41 42 45 46 6247 61org.hibernate.cfg.ImprovedNamingStrategy 48org.hibernate.dialect.MySQL5Dialect 49com.mysql.jdbc.Driver 50${database.url} 51${database.username} 52${database.password} 533 5418 5510 56update 57true 58true 59none 60
启动时报错,
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 23 8 9 104 5 6 7 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
其他配置不变