Search in sources :

Example 1 with IocBy

use of org.nutz.mvc.annotation.IocBy in project nutz by nutzam.

the class NutLoading method createIoc.

protected Ioc createIoc(NutConfig config, Class<?> mainModule) throws Exception {
    IocBy ib = mainModule.getAnnotation(IocBy.class);
    if (null != ib) {
        if (log.isDebugEnabled())
            log.debugf("@IocBy(type=%s, args=%s,init=%s)", ib.type().getName(), Json.toJson(ib.args()), Json.toJson(ib.init()));
        Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
        // 如果是 Ioc2 的实现,增加新的 ValueMaker
        if (ioc instanceof Ioc2) {
            ((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
        }
        // 如果给定了 Ioc 的初始化,则依次调用
        for (String objName : ib.init()) {
            ioc.get(null, objName);
        }
        // 保存 Ioc 对象
        Mvcs.setIoc(ioc);
        return ioc;
    } else if (log.isInfoEnabled())
        log.info("!!!Your application without @IocBy supporting");
    return null;
}
Also used : Ioc2(org.nutz.ioc.Ioc2) IocBy(org.nutz.mvc.annotation.IocBy) Ioc(org.nutz.ioc.Ioc)

Example 2 with IocBy

use of org.nutz.mvc.annotation.IocBy in project nutz by nutzam.

the class BaseNutTest method getIocConfigure.

/**
     * 子类可覆盖本方法,以配置项目的ioc配置,可选项
     */
protected String[] getIocConfigure() throws Exception {
    Class<?> klass = getMainModule();
    if (klass == null)
        return new String[] {};
    IocBy iocBy = klass.getAnnotation(IocBy.class);
    if (iocBy == null)
        return new String[] {};
    return iocBy.args();
}
Also used : IocBy(org.nutz.mvc.annotation.IocBy)

Aggregations

IocBy (org.nutz.mvc.annotation.IocBy)2 Ioc (org.nutz.ioc.Ioc)1 Ioc2 (org.nutz.ioc.Ioc2)1