NutzCN Logo
问答 Web项目使用 SimpleDataSource作为数据源报没有合适的驱动
发布于 2845天前 作者 Leewell1989 1800 次浏览 复制 上一个帖子 下一个帖子
标签:

SimpleDataSource在Web项目下使用是有Bug吗?
使用SimpleDataSource作为数据源,Junit可以正常使用,启动Web项目后,报如下错误,换成Druid正常。

17-3-9 15:5:30.334 WARN [http-bio-8080-exec-3] Error@/Login :
org.nutz.ioc.IocException: [userModule, userService, dao] # FAIL to create Ioc Bean name=[dao]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	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:225)
	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:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.nutz.dao.impl.NutDao'
 by args: [
  @(org.nutz.dao.impl.SimpleDataSource@1662250)] becasue:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/datanutz
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
	... 37 more
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/datanutz
	at java.sql.DriverManager.getConnection(DriverManager.java:602)
	at java.sql.DriverManager.getConnection(DriverManager.java:185)
	at org.nutz.dao.impl.SimpleDataSource.getConnection(SimpleDataSource.java:42)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:190)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:181)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:113)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	... 39 more

排查了驱动包版本问题、数据库种类问题(mysql/oracle)、项目配置问题(启动时是否完全加载项目中的jar包),最后换成连接池好了。

@Wendal 求解。

5 回复

因为mysql驱动 6.x移除了老驱动类,然后老版本的SimpleDataSource类只加载了那个类名,新版已fix

@wendal mysql驱动使用的5.x,nutz1.58,我换成1.6x试一下

@leewell1989 额,5.x驱动应该没事才对,实在不行就Classfor'Name一下,肯定work

换1.60也不行.ClassForName太麻烦了吧?我先用Druid了

添加回复
请先登陆
回到顶部