NutzCN Logo
问答 求助,报异常。。。
发布于 3330天前 作者 lwj11800 2692 次浏览 复制 上一个帖子 下一个帖子
标签: ioc
var ioc={
		 dataSource : {
		        type : "com.mchange.v2.c3p0.ComboPooledDataSource",
		        events : {
		            depose : 'close'
		        },
		        fields : {
		            driverClass : 'com.mysql.jdbc.Driver',
		            jdbcUrl : 'jdbc:mysql:///test',
		            user : 'root',
		            password : '11800'
		        }
		    },
		    dao:{
		    	type:"org.nutz.dao.impl.NutDao",
		    	args:[{ refer : "dataSource" }]
		    },
		    loginerService:{
		    	type:"com.service.impl.LoginerSerImpl",
		    	args:[{ refer : "dao" }]
		    }
}

@IocBean public class LoginerSerImpl implements LoginerService{ @Inject private Dao dao; @Override public void insertLog(Loginer loginer) { dao.insert(loginer); }
@IocBy(type = ComboIocProvider.class, args = {"*js","ioc/","*anno", "com.modules","*tx"})
@Modules(scanPackage=true)
public class ComeNutz {

}
@IocBean
public class LoginerAction {

	@Inject
	private LoginerService loginerService;
	
	@At("/insert")
	@Ok("redirect:select")
	public void inser(Loginer loginer){
		loginerService.insertLog(loginer);
	}

报错

 WARN [http-8080-2] - Error@/insert :
org.nutz.ioc.IocException: create ioc bean fail name=loginerAction ioc define:
{
   "type" :"com.modules.action.LoginerAction",
   "singleton" :true,
   "events" :{
   },
   "args" :[],
   "fields" :[{
      "name" :"loginerService",
      "value" :{
         "type" :"refer",
         "value" :"loginerService"
      },
      "optional" :false
   }],
   "scope" :"app"
}
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:132)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:194)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:212)
	
	Caused by: org.nutz.ioc.IocException: create ioc bean fail name=loginerService ioc define:
{
   "type" :"com.service.impl.LoginerSerImpl",
   "singleton" :true,
   "args" :[{
      "type" :"refer",
      "value" :"dao"
   }],
   "fields" :[],
   "scope" :"app"
}
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:132)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:194)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	
	Caused by: org.nutz.lang.born.BorningException: Fail to born 'com.service.impl.LoginerSerImpl'
 by args: [
  @(org.nutz.dao.impl.NutDao@2369ffec)]
	at org.nutz.lang.Mirror.getBorning(Mirror.java:895)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:96)
	... 28 more

这是哪儿错了?

8 回复
		    loginerService:{
		    	type:"com.service.impl.LoginerSerImpl",
		    	args:[{ refer : "dao" }]
		    }

其中args是构造方法参数, 你的类就没这样的构造方法, 我猜你应该能解决了

@wendal

  loginerService:{
		    	type:"com.service.impl.LoginerSerImpl",
		    	fields:[{
		    	      dao:{refer:"dao"}
		    	}]
		    }

改成样也不对,哪里错了吗?

@lwj11800 如何不对?是不是要给点出错信息呢?

@lwj11800 多写了一对[]号,太不小心了

这个类完全可以走注解,何必走js呢,为了部署时可以配置?

@wendal 新手,完全是按照入门教程来的,还不是很熟悉。

@lwj11800 nutzbook里面大部分的用户类都是走注解呢

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