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;
}
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();
}