NutzCN Logo
问答 nutzboot初始化怎么获取nutconfig
发布于 2219天前 作者 shine 2228 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean(create="init", depose="depose")
public class MainLauncher {
    
    @Inject
    protected PropertiesProxy conf;
    
    @At("/")
    @Ok("->:/index.html")
    public void index() {}
    
    public void init(NutConfig config) {
        // NB自身初始化完成后会调用这个方法
    	Ioc ioc = config.getIoc();
    	initBeetlFounction(config, ioc);
    }
    public void depose() {}

    public static void main(String[] args) throws Exception {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
    }

    private void initBeetlFounction(NutConfig config,Ioc ioc){
    	for (ViewMaker vm : config.getViewMakers()) {
            if (vm instanceof BeetlViewMaker) {
            	 ((BeetlViewMaker)vm).groupTemplate.registerFunctionPackage("temp_resource", ioc.get(TemplateResourceFounction.class));
            }
        }
    }
}

报错
org.nutz.ioc.IocException: IocBean[mainLauncher] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:160)
	at org.nutz.boot.NbApp._run(NbApp.java:193)
	at org.nutz.boot.NbApp.run(NbApp.java:170)
	at com.yuezhi.lxpc.MainLauncher.main(MainLauncher.java:35)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: Fail to find Method com.yuezhi.lxpc.MainLauncher->init with params:
[]
	at org.nutz.lang.Lang.wrapThrow(Lang.java:186)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:182)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	... 6 more
Caused by: java.lang.NoSuchMethodException: Fail to find Method com.yuezhi.lxpc.MainLauncher->init with params:
[]
	at org.nutz.lang.Mirror.findMethod(Mirror.java:1192)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:177)
	... 8 more
3 回复

你可以写在MainSetup里面嘛,不过, 有更好的写法了

    @Inject("refer:$ioc")
    Ioc ioc;
    @Inject
    GroupTemplate groupTemplate; // 已经在ioc容器中

    public void init() {
    	groupTemplate.registerFunctionPackage("temp_resource", ioc.get(TemplateResourceFounction.class));
    }

@wendal
注册自定义标签,更好的写法是什么?。。

我写了的,就是上面这个

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