org.nutz.ioc.Ioc类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(355)

本文整理了Java中org.nutz.ioc.Ioc类的一些代码示例,展示了Ioc类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ioc类的具体详情如下:
包路径:org.nutz.ioc.Ioc
类名称:Ioc

Ioc介绍

[英]Ioc 容器接口
[中]国际奥委会容器接口

代码示例

代码示例来源:origin: nutzam/nutz

  1. public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
  2. Ioc ioc = Mvcs.getIoc();
  3. if (null == ioc)
  4. throw new RuntimeException("You need define @IocBy in main module!!!");
  5. if (Strings.isBlank(objName))
  6. return ioc.get(objType);
  7. return ioc.get(objType, objName);
  8. }

代码示例来源:origin: nutzam/nutz

  1. names = ioc.getNamesByType(type);
  2. if (names != null && names.length == 1) {
  3. return ioc.get(type, names[0]);
  4. if (ioc.has(name)) {
  5. if (ioc instanceof Ioc2)
  6. return ((Ioc2)ioc).get(type, name, ctx);
  7. return ioc.get(type, name);
  8. return ((Ioc2)ioc).getByType(type, ctx);
  9. else
  10. return ioc.getByType(type);

代码示例来源:origin: nutzam/nutz

  1. L.set(Integer.TYPE);
  2. boolean flag = true;
  3. String[] names = ioc.getNames();
  4. Arrays.sort(names);
  5. for (String beanName : names) {
  6. if (!beanName.startsWith(AopConfigration.IOCNAME))
  7. continue;
  8. AopConfigration cnf = ioc.get(AopConfigration.class, beanName);
  9. list.add(cnf);
  10. if (cnf instanceof AnnotationAopConfigration)

代码示例来源:origin: nutzam/nutzboot

  1. public static DataSource getSlaveDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
  2. if (ioc.has("slaveDataSource")) {
  3. return ioc.get(DataSource.class, "slaveDataSource");
  4. } else {
  5. return _getSlaveDataSource(ioc, conf, prefix);
  6. }
  7. }

代码示例来源:origin: nutzam/nutzboot

  1. /**
  2. * 根据Class获取指定的Ioc Bean列表
  3. *
  4. * @param klass
  5. * 需要指定的Class类
  6. * @return 符合Class类的Ioc Bean列表
  7. */
  8. public <T> List<T> getBeans(Class<T> klass) {
  9. List<T> list = new ArrayList<>();
  10. for (String name : getIoc().getNamesByType(klass)) {
  11. if (name == null)
  12. continue;
  13. list.add(getIoc().get(klass, name));
  14. }
  15. return list;
  16. }

代码示例来源:origin: nutzam/nutzboot

  1. webSecurityManager.setSessionManager(ioc.get(WebSessionManager.class, "shiroWebSessionManager"));
  2. for (String realmName : ioc.getNamesByType(Realm.class)) {
  3. AuthorizingRealm realm = ioc.get(AuthorizingRealm.class, realmName);
  4. if (conf.getBoolean(PROP_REALM_CACHE_ENABLE, false)) {
  5. realm.setCacheManager(ioc.get(CacheManager.class, "shiroCacheManager"));
  6. if (ioc.has("authenticationStrategy")) {
  7. ModularRealmAuthenticator modularRealmAuthenticator = new ModularRealmAuthenticator();
  8. modularRealmAuthenticator.setAuthenticationStrategy(ioc.get(AuthenticationStrategy.class, "authenticationStrategy"));
  9. if (realms.size() > 0)
  10. modularRealmAuthenticator.setRealms(realms);
  11. webSecurityManager.setRememberMeManager(ioc.get(RememberMeManager.class, "shiroRememberMeManager"));
  12. return webSecurityManager;

代码示例来源:origin: nutzam/nutzboot

  1. protected Object createTest() throws Exception {
  2. if (hasIocBean)
  3. return getIoc().get(getTestClass().getJavaClass());
  4. Object obj = getTestClass().getJavaClass().newInstance();
  5. for (Field field : fields) {
  6. field.set(obj, getIoc().getByType(field.getType()));
  7. }
  8. return obj;
  9. }

代码示例来源:origin: nutzam/nutzboot

  1. /**
  2. * 容器初始化时,初始化Spring Mvc的Ioc容器,并放入ServletContext
  3. */
  4. public void contextInitialized(ServletContextEvent sce) {
  5. applicationContext = new XmlWebApplicationContext();
  6. applicationContext.setServletContext(sce.getServletContext());
  7. applicationContext.setConfigLocation(configLocation);
  8. applicationContext.refresh();
  9. appContext.getComboIocLoader().addLoader(new SpringIocLoader2(applicationContext, getSpringBeanNames().toArray(new String[0])));
  10. sce.getServletContext().setAttribute("spring." + selfName, applicationContext);
  11. // 登记所有标注了@AsSpringBean的对象到spring ioc
  12. Ioc ioc = appContext.getIoc();
  13. for (String name : ioc.getNamesByAnnotation(AsSpringBean.class)) {
  14. applicationContext.getBeanFactory().registerSingleton(name, ioc.get(null, name));
  15. }
  16. }

代码示例来源:origin: nutzam/nutz

  1. public boolean has(String key) {
  2. if (key == null)
  3. return false;
  4. if ("sys".equals(key))
  5. return true;
  6. if ("env".equals(key))
  7. return true;
  8. if ("$ioc".equals(key))
  9. return true;
  10. if (key.startsWith("$") && key.length() > 1)
  11. return ioc.has(key.substring(1));
  12. return super.has(key);
  13. }

代码示例来源:origin: nutzam/nutzboot

  1. public void prepareIoc() {
  2. if (ctx.getIoc() == null) {
  3. ctx.setIoc(new NutIoc(ctx.getComboIocLoader()));
  4. }
  5. // 把核心对象放进ioc容器
  6. if (!ctx.ioc.has("appContext")) {
  7. ctx.ioc.addBean("appContext", ctx);
  8. ctx.ioc.addBean("conf", ctx.getConf());
  9. ctx.ioc.addBean("nbApp", this);
  10. // 添加更多扩展bean
  11. ctx.ioc.addBean("counterService", new MemoryCounterService());
  12. }
  13. Mvcs.ctx().iocs.put("nutz", ctx.getIoc());
  14. }

代码示例来源:origin: nutzam/nutz

  1. public Object getByType(Ioc ioc, IocContext ctx) {
  2. if (ioc instanceof Ioc2)
  3. return ((Ioc2)ioc).getByType(type, ctx);
  4. else
  5. return ioc.getByType(type);
  6. }
  7. }

代码示例来源:origin: nutzam/nutzboot

  1. public static DataSource getManySlaveDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
  2. if (ioc.has(prefix + "slaveDataSource")) {
  3. return ioc.get(DataSource.class, prefix + "slaveDataSource");
  4. } else {
  5. return _getSlaveDataSource(ioc, conf, prefix);
  6. }
  7. }

代码示例来源:origin: org.nutz/nutzboot-core

  1. /**
  2. * 根据Class获取指定的Ioc Bean列表
  3. *
  4. * @param klass
  5. * 需要指定的Class类
  6. * @return 符合Class类的Ioc Bean列表
  7. */
  8. public <T> List<T> getBeans(Class<T> klass) {
  9. List<T> list = new ArrayList<>();
  10. for (String name : getIoc().getNamesByType(klass)) {
  11. if (name == null)
  12. continue;
  13. list.add(getIoc().get(klass, name));
  14. }
  15. return list;
  16. }

代码示例来源:origin: nutzam/nutz

  1. for (int i = 0; i < vms.value().length; i++) {
  2. if (vms.value()[i].getAnnotation(IocBean.class) != null && ioc != null) {
  3. makers.add(ioc.get(vms.value()[i]));
  4. } else {
  5. makers.add(Mirror.me(vms.value()[i]).born());
  6. String[] names = ioc.getNames();
  7. Arrays.sort(names);
  8. for (String name : ioc.getNames()) {
  9. if (name != null && name.startsWith(ViewMaker.IOCNAME)) {
  10. log.debug("add ViewMaker from Ioc by name=" + name);
  11. makers.add(ioc.get(ViewMaker.class, name));

代码示例来源:origin: nutzam/nutz

  1. injectName);
  2. injectName = ai.getInjectName();
  3. if (!ioc.has(injectName)) {
  4. log.warnf("Moudle with @InjectName('%s') or @IocBean('%s') but no such ioc bean found!! Pls check your ioc configure!!",
  5. injectName,

代码示例来源:origin: org.nutz/nutzboot-core

  1. public void prepareIoc() {
  2. if (ctx.getIoc() == null) {
  3. ctx.setIoc(new NutIoc(ctx.getComboIocLoader()));
  4. }
  5. // 把核心对象放进ioc容器
  6. if (!ctx.ioc.has("appContext")) {
  7. ctx.ioc.addBean("appContext", ctx);
  8. ctx.ioc.addBean("conf", ctx.getConf());
  9. ctx.ioc.addBean("nbApp", this);
  10. // 添加更多扩展bean
  11. ctx.ioc.addBean("counterService", new MemoryCounterService());
  12. }
  13. Mvcs.ctx().iocs.put("nutz", ctx.getIoc());
  14. }

代码示例来源:origin: org.nutz/nutz

  1. public Object getByType(Ioc ioc, IocContext ctx) {
  2. if (ioc instanceof Ioc2)
  3. return ((Ioc2)ioc).getByType(type, ctx);
  4. else
  5. return ioc.getByType(type);
  6. }
  7. }

代码示例来源:origin: nutzam/nutz

  1. public List<? extends MethodInterceptor> makeIt(Aop t, Method method, Ioc ioc) {
  2. List<MethodInterceptor> list = new ArrayList<MethodInterceptor>();
  3. for (String name : t.value()) {
  4. list.add(ioc.get(MethodInterceptor.class, name));
  5. }
  6. return list;
  7. }
  8. }

代码示例来源:origin: org.nutz/nutzboot-starter-jdbc

  1. public static DataSource getSlaveDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
  2. if (ioc.has("slaveDataSource")) {
  3. return ioc.get(DataSource.class, "slaveDataSource");
  4. } else {
  5. return _getSlaveDataSource(ioc, conf, prefix);
  6. }
  7. }

代码示例来源:origin: nutzam/nutzboot

  1. public void init() {
  2. Map<String, CacheStrategy> map = new HashMap<>();
  3. String[] types = ioc.getNamesByType(KeyStringifier.class);
  4. if (Lang.isEmptyArray(types)) {
  5. this.stringifier = String::valueOf;
  6. } else {
  7. this.stringifier = ioc.get(KeyStringifier.class, types[0]);

相关文章