Nuta连接池配置问题

发布于 2021-11-27 16:35:00 字数 4172 浏览 693 评论 3

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



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑红尘 2021-11-28 15:57:43

名字写错了吧

从异常里很容易看出:

Fail to eval Injector for field: 'user'
...
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
...
Caused by: java.lang.NoSuchFieldException: Can NOT find field [user] in class [com.alibaba.druid.pool.DruidDataSource] and it's parents classes

是字段名错了,应该是

...
    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 的与各个连接池的用法,请参看  http://nutzam.com/core/appendix/create_datasource.html

野心澎湃 2021-11-28 14:33:53

jar都不缺,原因是这个: c3p0的写法:<property name="user" value="${jdbc.username}" /> druid连接池:<property name="username" value="${jdbc.username}"/>

做个少女永远怀春 2021-11-28 10:40:25

用了温少的连接池,是不是没有把jar包加进去啊

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文