NutzCN Logo
问答 工厂方法的使用问题
发布于 3179天前 作者 Rekoe 2148 次浏览 复制 上一个帖子 下一个帖子
标签:

RT

igronSheetList:{
		factory : "java.util.ArrayList#addAll",
		 args : ["ShuoMing"]
	}

错误

Caused by: org.nutz.ioc.IocException: Fail to find Method java.util.ArrayList->addAll with params:
["java.lang.String"] FAIL to create Ioc Bean name=[igronSheetList]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:147)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:204)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
	at com.shanggame.AppSetup.init(AppSetup.java:51)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
	... 16 more
Caused by: java.lang.NoSuchMethodException: Fail to find Method java.util.ArrayList->addAll with params:
["java.lang.String"]
	at org.nutz.lang.Mirror.findMethod(Mirror.java:1140)
	at org.nutz.lang.Mirror.findMethod(Mirror.java:1116)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:101)
	... 21 more
13 回复

工厂方法需要时个静态方法呢

@wendal
那我如何配置一个 字符串的 list 数据 到ioc中

写个静态方法,然后返回需要的对象

@wendal
单独list没戏啦

来自 iPhone 6

@Rekoe 肯定可以啊,待我写段demo。代码给你


array : { type : "java.util.ArrayList", args : [["wendal", "zozoh", "pangwu"]] }

读取

System.out.println(ioc.get(List.class, "array").toString());

输出

[wendal, zozoh, pangwu]

@wendal
为啥我的报这个错误

2016-03-04 13:14:39,611 [ERROR][org.nutz.mvc.impl.NutLoading] - Error happend during start serivce!
org.nutz.ioc.IocException: Prohibited package name: java.util For object [array] - type:[interface java.util.List]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:211)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
	at com.shanggame.AppSetup.init(AppSetup.java:50)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.SecurityException: Prohibited package name: java.util
	at java.lang.ClassLoader.preDefineClass(Unknown Source)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:70)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:56)
	at org.nutz.aop.DefaultClassDefiner.define(DefaultClassDefiner.java:24)
	at org.nutz.aop.asm.AsmClassAgent.generate(AsmClassAgent.java:47)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:58)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:45)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:102)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:36)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:204)
	... 20 more
2016-03-04 13:14:39,626 [ERROR][org.nutz.mvc.impl.NutLoading] - try to depose ioc
三月 04, 2016 1:14:39 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: Prohibited package name: java.util For object [array] - type:[interface java.util.List]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:988)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:165)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.nutz.ioc.IocException: Prohibited package name: java.util For object [array] - type:[interface java.util.List]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:211)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
	at com.shanggame.AppSetup.init(AppSetup.java:50)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
	... 16 more
Caused by: java.lang.SecurityException: Prohibited package name: java.util
	at java.lang.ClassLoader.preDefineClass(Unknown Source)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:70)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:56)
	at org.nutz.aop.DefaultClassDefiner.define(DefaultClassDefiner.java:24)
	at org.nutz.aop.asm.AsmClassAgent.generate(AsmClassAgent.java:47)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:58)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:45)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:102)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:36)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:204)
	... 20 more
三月 04, 2016 1:14:39 下午 org.apache.catalina.core.StandardContext startInternal

你配置了某些泛指的aop?

继承ArrayList做个类吧

@wendal
$aop : { type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration', fields : { itemList : [ [ '.+', 'toString', 'ioc:log' ], [ 'com\\.rekoe\\.msg\\.handler\\..+', '(doHandler)+','ioc:msgHadhler' ], [ 'com\\.rekoe\\.db\\.service\\.impl\\..+', '(update)+','ioc:txREPEATABLE_READ' ], ] } }

@wendal
去掉那个日志的aop了

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