Tapestry 5.4 未找到用于休眠的驱动程序
Posted
技术标签:
【中文标题】Tapestry 5.4 未找到用于休眠的驱动程序【英文标题】:Driver not found for hibernate with Tapestry 5.4 【发布时间】:2013-12-07 20:37:30 【问题描述】:我正在尝试将项目升级到 Tapestry 5.4,因为我想使用 Bootstrap。目前它使用 Tapestry-hibernate 5.3.7 和 mysql。几乎一切正常。但是当我尝试使用 Hibernate 时,它显示“没有为 jdbc:mysql://localhost:3306/databaseName 找到合适的驱动程序”。
现在,之前有人问过这个问题,答案是“驱动程序不在类路径上”或“您输入的 url 错误”。但我绝对 100% 肯定司机在那里。它在战争文件中。这是 pom.xml 中的条目:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
而且我绝对 100% 确定我输入了正确的网址,因为它适用于 Tapestry 5.3.7。
我也尝试过手动添加驱动程序。另外,我尝试了其他数据库,并且给出了相同的错误。我在下面粘贴了堆栈跟踪。查看 java.sql.DriverManager.getConnection 的源代码,它似乎正在检查驱动程序列表,但该列表为空。
[ERROR] hbm2ddl.SchemaUpdate HHH000299: Could not complete schema update
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/preparedMindDatabase
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:192)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:495)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1779)
at org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl.<init>(HibernateSessionSourceImpl.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:49)
at org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60)
at org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
at org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
at org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63)
at org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54)
at org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:66)
at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:54)
at $HibernateSessionSource_61fa1b0ff12.delegate(Unknown Source)
at $HibernateSessionSource_61fa1b0ff12.create(Unknown Source)
at org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.<init>(HibernateSessionManagerImpl.java:31)
at org.apache.tapestry5.hibernate.modules.HibernateCoreModule.buildHibernateSessionManager(HibernateCoreModule.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:51)
at org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60)
at org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:60)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at org.apache.tapestry5.ioc.internal.services.PerThreadServiceCreator.createObject(PerThreadServiceCreator.java:47)
at $HibernateSessionManager_61fa1b0ffd3.delegate(Unknown Source)
at $HibernateSessionManager_61fa1b0ffd3.getSession(Unknown Source)
at $HibernateSessionManager_61fa1b0ff4e.getSession(Unknown Source)
at $Session_61fa1b0ffd2.readProperty(Unknown Source)
at $Session_61fa1b0ffd2.createCriteria(Unknown Source)
at $Session_61fa1b0fef9.createCriteria(Unknown Source)
at com.salsaberries.preparedmind.pages.Register.advised$onSuccess_61fa1b0ffbf(Register.java:57)
at com.salsaberries.preparedmind.pages.Register$Invocation_onSuccess_61fa1b0ffbe.proceedToAdvisedMethod(Unknown Source)
at org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:84)
at org.apache.tapestry5.internal.hibernate.CommitAfterWorker$1.advise(CommitAfterWorker.java:53)
at org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
at com.salsaberries.preparedmind.pages.Register.onSuccess(Register.java)
at com.salsaberries.preparedmind.pages.Register.dispatchComponentEvent(Register.java)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:942)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1127)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3100(ComponentPageElementImpl.java:62)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1072)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1069)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:145)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1068)
at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerContextEvent(InternalComponentResourcesImpl.java:302)
at org.apache.tapestry5.corelib.components.Form.onAction(Form.java:526)
at org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:942)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1127)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3100(ComponentPageElementImpl.java:62)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1072)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1069)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:80)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:89)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1112)
at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:145)
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1068)
at org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75)
at org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
at $ComponentEventRequestHandler_61fa1b0ffd1.handle(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$37.handle(TapestryModule.java:2202)
at $ComponentEventRequestHandler_61fa1b0ffd1.handle(Unknown Source)
at $ComponentEventRequestHandler_61fa1b0ff5c.handle(Unknown Source)
at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
at org.apache.tapestry5.services.InitializeActivePageName.handleComponentEvent(InitializeActivePageName.java:39)
at $ComponentRequestHandler_61fa1b0ff5e.handleComponentEvent(Unknown Source)
at org.apache.tapestry5.internal.services.RequestOperationTracker$1.perform(RequestOperationTracker.java:55)
at org.apache.tapestry5.internal.services.RequestOperationTracker$1.perform(RequestOperationTracker.java:52)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.perform(OperationTrackerImpl.java:107)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.perform(PerThreadOperationTracker.java:100)
at org.apache.tapestry5.ioc.internal.RegistryImpl.perform(RegistryImpl.java:1117)
at org.apache.tapestry5.internal.services.RequestOperationTracker.handleComponentEvent(RequestOperationTracker.java:47)
at $ComponentRequestHandler_61fa1b0ff5e.handleComponentEvent(Unknown Source)
at com.salsaberries.preparedmind.filters.HTTPHeaderFilter.handleComponentEvent(HTTPHeaderFilter.java:46)
at $ComponentRequestFilter_61fa1b0ff5b.handleComponentEvent(Unknown Source)
at $ComponentRequestHandler_61fa1b0ff5e.handleComponentEvent(Unknown Source)
at com.salsaberries.preparedmind.filters.SecurityFilter.handleComponentEvent(SecurityFilter.java:62)
at $ComponentRequestFilter_61fa1b0ff5a.handleComponentEvent(Unknown Source)
at $ComponentRequestHandler_61fa1b0ff5e.handleComponentEvent(Unknown Source)
at $ComponentRequestHandler_61fa1b0ff23.handleComponentEvent(Unknown Source)
at org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
at $Dispatcher_61fa1b0ff26.dispatch(Unknown Source)
at $Dispatcher_61fa1b0ff20.dispatch(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:300)
at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
at $RequestHandler_61fa1b0ff21.service(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$3.service(TapestryModule.java:845)
at $RequestHandler_61fa1b0ff21.service(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$2.service(TapestryModule.java:835)
at $RequestHandler_61fa1b0ff21.service(Unknown Source)
at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:89)
at $RequestHandler_61fa1b0ff21.service(Unknown Source)
at $RequestHandler_61fa1b0ff17.service(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:251)
at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:59)
at $HttpServletRequestHandler_61fa1b0ff19.service(Unknown Source)
at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
at $HttpServletRequestFilter_61fa1b0ff14.service(Unknown Source)
at $HttpServletRequestHandler_61fa1b0ff19.service(Unknown Source)
at org.apache.tapestry5.modules.TapestryModule$1.service(TapestryModule.java:795)
at $HttpServletRequestHandler_61fa1b0ff19.service(Unknown Source)
at $HttpServletRequestHandler_61fa1b0ff13.service(Unknown Source)
at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:166)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
编辑:这里是休眠配置:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/preparedMindDatabase</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">*******</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
</session-factory>
【问题讨论】:
【参考方案1】:hibernate jar 在哪里?也许你遇到了一些奇怪的情况,hibernate 是由 bootstrap 类加载器加载的,但驱动程序是由 war 类加载器加载的。
【讨论】:
这很有趣,这里不是这样,但升级时可能会导致同样的问题。【参考方案2】:看看抛出异常的 java.sql.DriverManager#getConnection 方法,它似乎是两种可能性之一:
驱动程序没有注册自己。现代驱动程序在加载类时自动注册自己
驱动程序注册了自己,但调用者的类加载器看不到它,因此它被跳过了。
我建议在 java.sql.DriverManager#getConnection 和 java.sql.DriverManager#registerDriver 上放置一些断点,看看发生了什么。
奇怪的是为什么它以前可以工作。通常我们应该将驱动程序放在 $TOMCAT_HOME/lib 中,参见this post。它对应用程序的任何部分始终可见,并防止多次注册驱动程序。
尝试从 WAR 中删除驱动程序并确保它位于 $TOMCAT_HOME/lib 中。如果它不起作用,您可以随时通过进一步的发现来编辑问题,希望它有所帮助。
【讨论】:
问题是 Tomcat 仍在加载旧驱动程序,当我更新到新驱动程序时,它也尝试加载它,这导致了一些冲突。按照您的建议将驱动程序放入 $TOMCAT_HOME/lib 并将其从 WAR 中删除(并清除 tomcat webapps 文件夹)解决了问题,谢谢!以上是关于Tapestry 5.4 未找到用于休眠的驱动程序的主要内容,如果未能解决你的问题,请参考以下文章
tapestry3笔记--tapestry 初探,《 tapestry in action 》第一章学习笔记
休眠 Java:未找到函数“AES_DECRYPT”; SQL 语句: