当我尝试在Tomcat 7上运行我的JSF应用程序时,它会抛出此异常.
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:192)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:278)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
... 51 more
如果我在创建EntitiyManagerFactory之前添加此行,它可以正常工作.
Class.forName("com.mysql.jdbc.Driver");
emf = Persistence.createEntityManagerFactory("manager1");
我的依赖是
org.hibernate
hibernate-entitymanager
4.1.2.Final
mysql
mysql-connector-java
5.1.19
我的应用程序也可以正常运行tomcat 6,而无需添加Class.forName(“com.mysql.jdbc.Driver”);
有什么想法解决这个问题吗?谢谢