开发者社区> 问答> 正文

Nuta连接池配置问题?报错

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



展开
收起
爱吃鱼的程序员 2020-06-14 22:51:49 479 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    用了温少的连接池,是不是没有把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

    2020-06-14 22:52:06
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载