NutzCN Logo
问答 本人新手入门,为什么按照新手入门教程一步一步来的还是报异常?
发布于 3313天前 作者 lwj11800 2888 次浏览 复制 上一个帖子 下一个帖子
标签: nutzbook

配置连接池

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" }]
		    }
}

入口主函数

@IocBy(type = ComboIocProvider.class, args = {"*js","*anno", "com.modules","*tx"})
@Modules(scanPackage=true)
public class ComeNutz {

}

action

@IocBean
public class LoginerAction {

	@Inject
	private Dao dao;
	
	@At("/login")
	@Ok("redirect:login.jsp")
	public void login(){
		int i=dao.count(Loginer.class);
		System.out.println("==============="+i);
	}

web.xml配置

 <filter>  
        <filter-name>entrance</filter-name>  
        <filter-class>org.nutz.mvc.NutFilter</filter-class>  
        <init-param>  
            <param-name>modules</param-name>  
            <param-value>com.modules.ComeNutz</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>entrance</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  

启动不报错,请求/login,报错

 WARN [http-8080-2] - Error@/login :
org.nutz.ioc.IocException: create ioc bean fail name=loginerAction ioc define:
{
   "type" :"com.modules.action.LoginerAction",
   "singleton" :true,
   "events" :{
   },
   "args" :[],
   "fields" :[{
      "name" :"dao",
      "value" :{
         "type" :"refer",
         "value" :"dao"
      },
      "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)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:106)
	...
	Caused by: org.nutz.ioc.IocException: For object [dao] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:201)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
	...
	Caused by: org.nutz.ioc.ObjectLoadException: Object 'dao' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:140)
	at org.nutz.ioc.loader.cached.CachedIocLoaderImpl.load(CachedIocLoaderImpl.java:47)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:169)
	... 27 more

哪里错了呢,求解释!

8 回复
@IocBy(type = ComboIocProvider.class, args = {"*js","*anno", "com.modules","*tx"})

肯定抄错, *js后面还有其参数, 而不是马上*anno

@wendal 我仔细看了看,他后面有个"*js", "ioc/", 问题是我就js文件就放在src下的,不需要“ioc/”啊

@lwj11800 别直接放在src下!!!

@wendal 这只是路径不规范吧,跟报错好像没有关系吧

@wendal 改了,没异常了!能不能解释一下原因呢,谢谢了

http://nutzbook.wendal.net/setup30mins/configure_iocby.html 这里已经说了吧

不存在默认路径, 必须给个路径

@wendal 知道了,下次不会在犯了!!!

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