NutzCN Logo
问答 org.nutz.ioc.ObjectLoadException: Object 'userModule' without define
发布于 3327天前 作者 明天会吹什么风 3894 次浏览 复制 上一个帖子 下一个帖子
标签: ioc
    公司正在考虑引用Nutz,让我来研究如何使用Nutz!于是我找来“Nutzbook”手册向导,来一步步建立一个web工程,但是到编写第一个模块类UserModule的时候,遇到了下列问题(之前的步骤全都正确执行,tomcat也能正常启动无报错)

    1. 异常信息
         2015-10-14 15:10:48.530 DEBUG [http-bio-8081-exec-3] Found mapping for [GET] path=/user/login : UserModule.login(...)

2015-10-14 15:10:48.533 DEBUG [http-bio-8081-exec-3] Get 'userModule'<class net.wendal.nutzbook.module.UserModule>
2015-10-14 15:10:48.534 DEBUG [http-bio-8081-exec-3] >> Load definition
2015-10-14 15:10:48.535 WARN [http-bio-8081-exec-3] Error@/user/login :
org.nutz.ioc.IocException: For object [userModule] - type:[class net.wendal.nutzbook.module.UserModule]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:201)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:212)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:106)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:40)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:182)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'userModule' 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)
... 26 more

  1. 各个文件
    (1) MainModule.java
    package net.wendal.nutzbook;

import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class,args={"*js","ioc/","*anno","net.wendal.netzbook","*tx"})

@Modules(scanPackage=true)
public class MainModule {
}

(2)MainSetup.java
public class MainSetup implements Setup{

@Override
public void destroy(NutConfig conf) {
    // TODO Auto-generated method stub
}

@Override
public void init(NutConfig conf) {
    Ioc ioc = conf.getIoc();
    Dao dao = ioc.get(Dao.class);
    Daos.createTablesInPackage(dao, "net.wendal.netzbook", false);

    //初始化默认根用户
    if(dao.count(User.class) == 0){
       User user = new User();
       user.setName("admin");
       user.setPassword("123456");
       user.setCreateTime(new Date());
       user.setUpdateTime(new Date());
       dao.insert(user);
    }
}

}

求解答,如还需要知道些什么信息,请告知,谢谢!

6 回复

UserModule 文件加 @IocBean了么

@IocBy(type=ComboIocProvider.class,args={"*js","ioc/","*anno","net.wendal.netzbook","*tx"})

应该是

@IocBy(type=ComboIocProvider.class,args={"*js","ioc/","*anno","net.wendal.nutzbook","*tx"})

应该是

@IocBy(type=ComboIocProvider.class,args={"*json","ioc/","*anno","net.wendal.nutzbook","*tx"})

@Rekoe *js 与 *json 等价的

@Rekoe 详细定义在ComboIocLoader里面, 里面有全部缩写

            loaders.put("js", JsonLoader.class);
            loaders.put("json", JsonLoader.class);
            loaders.put("xml", XmlIocLoader.class);
            loaders.put("annotation", AnnotationIocLoader.class);
            loaders.put("anno", AnnotationIocLoader.class);
            loaders.put("trans", TransIocLoader.class);
            loaders.put("tx", TransIocLoader.class);
            try {
                loaders.put("cache",
                            (Class<? extends IocLoader>) Lang.loadClass("org.nutz.jcache.NutCacheIocLoader"));
            }
            catch (ClassNotFoundException e) {}
            try {
                loaders.put("quartz",
                            (Class<? extends IocLoader>) Lang.loadClass("org.nutz.integration.quartz.QuartzIocLoader"));
            }
            catch (ClassNotFoundException e) {}
添加回复
请先登陆
回到顶部