NutzCN Logo
问答 无法注入refer:$ioc对象?
发布于 2739天前 作者 qinerg 1990 次浏览 复制 上一个帖子 下一个帖子
标签:

写了个简单的bean,注入ioc对象时总出错,不知是为什么?

public class TestBean {
	private Log log = Logs.get();
	private Ioc ioc;
	public void init() {
		log.debug(ioc);
	}
}

使用json配置加载对象:

                String json = "{bean:{type:'test.TestBean',events:{create:'init'},fields:{'ioc':'refer:$ioc'}}}";
		Reader reader = new StringReader(json);
		Ioc ioc = new NutIoc(new JsonLoader(reader));
		
		TestBean eventBus = ioc.get(TestBean.class, "bean");

报错信息为:

Fail to set value by field
org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <org.nutz.ioc.Ioc> for {refer:$ioc} because:
BorningException:Fail to born 'org.nutz.ioc.Ioc'
 by args: [
  @(refer:$ioc)] because: No suitable Constructor or Factory Method!!

是声明的方式不正确么?

2 回复
String json = "{bean:{type:'test.TestBean',events:{create:'init'},fields:{'ioc':{refer:'$ioc'}}}}";

奥,明白了,thx !

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