var ioc = { dataSource: { //type: "com.mchange.v2.c3p0.ComboPooledDataSource", type : "com.alibaba.druid.pool.DruidDataSource", events : { depose : 'close' }, fields: { driverClass: 'com.mysql.jdbc.Driver', jdbcUrl: 'jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8', user: 'root', password: 'root', testWhileIdle:true } }, dao : { type : 'org.nutz.dao.impl.NutDao', args : [{refer:'dataSource'}] } };这样写之后报错
java.lang.RuntimeException: Fail to eval Injector for field: 'user' at org.nutz.lang.Lang.wrapThrow(Lang.java:121) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:88) at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:182) at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:66) at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:182) at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24) at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:23) at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:95) at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:182) at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24) at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:23) at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:95) at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:182) at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:72) 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:36) at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:66) at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:30) at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:97) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: Can NOT find field [user] in class [com.alibaba.druid.pool.DruidDataSource] and it's parents classes at org.nutz.lang.Lang.wrapThrow(Lang.java:138) at org.nutz.lang.Mirror.getInjecting(Mirror.java:950) at org.nutz.ioc.weaver.FieldInjector.create(FieldInjector.java:13) at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:85) ... 35 more Caused by: java.lang.NoSuchFieldException: Can NOT find field [user] in class [com.alibaba.druid.pool.DruidDataSource] and it's parents classes at org.nutz.lang.Mirror.getField(Mirror.java:435) at org.nutz.lang.Mirror.getInjecting(Mirror.java:941) ... 37 more
用了温少的连接池,是不是没有把jar包加进去啊jar都不缺,原因是这个:c3p0的写法:<propertyname="user"value="${jdbc.username}"/>druid连接池:<propertyname="username"value="${jdbc.username}"/>
名字写错了吧
从异常里很容易看出:
FailtoevalInjectorforfield:'user'...Causedby:java.lang.RuntimeException:java.lang.NoSuchFieldException:CanNOTfindfield[user]inclass[com.alibaba.druid.pool.DruidDataSource]andit'sparentsclasses...Causedby:java.lang.NoSuchFieldException:CanNOTfindfield[user]inclass[com.alibaba.druid.pool.DruidDataSource]andit'sparentsclasses是字段名错了,应该是
...type:"com.alibaba.druid.pool.DruidDataSource",events:{depose:'close'},fields:{driverClass:'com.mysql.jdbc.Driver',jdbcUrl:'jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8',username:'root',password:'root'}}...
即,是"username"而不是"user"
更多关于Nutz的与各个连接池的用法,请参看 <atarget="_blank"rel="nofollow">http://nutzam.com/core/appendix/create_datasource.html
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。