NutzCN Logo
问答 ioc 构造参数传入map 报错
发布于 2582天前 作者 tiankongkm 1802 次浏览 复制 上一个帖子 下一个帖子
标签:
			args : [{"ds_0":{refer:"dataSource"}}],

请问这么写格式有错吗

6 回复

这样
args : [ {refer :'dataSource'}],

@qq_2b6bbb2b 需要传入一个map {"name":datasource} 这种的

把上下文贴一下,你要做什么?

args是构造方法注入,type的构造方法要和args能匹配才行

@qq_2b6bbb2b

	shardingDataSource : {
			factory : "com.tiankong.core.sharding.ShardingFactory#make",
	        type : "com.alibaba.druid.pool.DruidDataSource",
	        args : [{"ds_0":{refer:"dataSource"}}],
	        events : {
	        	create : "init",
	            depose : "close"
	        }
	    }
Exception in thread "main" org.nutz.ioc.IocException: IocBean[shardingDao -> shardingDataSource] throw Exception when creating
	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.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at com.tiankong.core.DubboStart.main(DubboStart.java:25)
2017-11-28 17:34:33,108 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'shardingDao' from [app] 
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.ioc.trigger.MethodEventTrigger.trigger(MethodEventTrigger.java:18)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:72)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 6 more

make方法返回的是个接口 datasource、

@qq_2b6bbb2b 搞定了 thank

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