NutzCN Logo
精华 手动初始化的Ioc容器怎么绑定到Mvcs中
发布于 2901天前 作者 cafebabe 2379 次浏览 复制 上一个帖子 下一个帖子
标签:

jar项目 main方法中new了一个Ioc容器,后面通过jetty来初始NutFilter的时候直接报NPE了

17:38:18,210 [ERROR] [main] log.warn - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@78429d6b{/,file:/E:/workspace/warfare_trunk/WebRoot}
org.nutz.mvc.LoadingException: java.lang.RuntimeException: Moudle with @InjectName('null') or @IocBean('null') but you not declare a Ioc for this app!! Miss @IocBy at MainMdoule??
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	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:990)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:196)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:135)
	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.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
	at org.mortbay.jetty.Server.doStart(Server.java:224)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
	at com.wabao.web.WebServer.start(WebServer.java:90)
	at com.wabao.core.GameContext.startWithWeb(GameContext.java:108)
	at com.wabao.bootstrap.GameWebMain.main(GameWebMain.java:29)
Caused by: java.lang.RuntimeException: Moudle with @InjectName('null') or @IocBean('null') but you not declare a Ioc for this app!! Miss @IocBy at MainMdoule??
	at org.nutz.lang.Lang.makeThrow(Lang.java:131)
	at org.nutz.mvc.impl.processor.ModuleProcessor.init(ModuleProcessor.java:72)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:204)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
	... 17 more
3 回复

1.b.50版本不会出现这个NPE,今天升级了一下就这样了

写个类实现IocProvider, 然后@IocBy引用它

public class MyIocProvider implements IocProvider {
    public static Ioc ioc;
    public Ioc create(NutConfig config, String[] args) {
	    return ioc;
	}
}
添加回复
请先登陆
回到顶部