org.nutz.ioc.Ioc.addBean()方法的使用及代码示例

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

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

Ioc.addBean介绍

暂无

代码示例

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

public void prepareIoc() {
  if (ctx.getIoc() == null) {
    ctx.setIoc(new NutIoc(ctx.getComboIocLoader()));
  }
  // 把核心对象放进ioc容器
  if (!ctx.ioc.has("appContext")) {
    ctx.ioc.addBean("appContext", ctx);
    ctx.ioc.addBean("conf", ctx.getConf());
    ctx.ioc.addBean("nbApp", this);
    // 添加更多扩展bean
    ctx.ioc.addBean("counterService", new MemoryCounterService());
  }
  Mvcs.ctx().iocs.put("nutz", ctx.getIoc());
}

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

public void prepareIoc() {
  if (ctx.getIoc() == null) {
    ctx.setIoc(new NutIoc(ctx.getComboIocLoader()));
  }
  // 把核心对象放进ioc容器
  if (!ctx.ioc.has("appContext")) {
    ctx.ioc.addBean("appContext", ctx);
    ctx.ioc.addBean("conf", ctx.getConf());
    ctx.ioc.addBean("nbApp", this);
    // 添加更多扩展bean
    ctx.ioc.addBean("counterService", new MemoryCounterService());
  }
  Mvcs.ctx().iocs.put("nutz", ctx.getIoc());
}

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

private void injectManyDao() {
  // 正则匹配多数据库url
  String regex = "jdbc\\.many\\.(\\w*)\\.url";
  for (String key : conf.getKeys()) {
    Pattern pattern = Regex.getPattern(regex);
    Matcher match = pattern.matcher(key);
    if(match.find()) {
      // 获取数据库名称
      String name = match.group(1);
      String prefix_name = "jdbc.many." + name + ".";
      DataSource manyDataSource = DataSourceStarter.createManyDataSource(ioc, conf, prefix_name);
      NutDao nutDao = new NutDao();
      nutDao.setDataSource(manyDataSource);
      // 处理对应的从库
      String slave_prefix = prefix_name + "slave.";
      DataSource slaveDataSource = DataSourceStarter.getManySlaveDataSource(ioc, conf, slave_prefix);
      if(slaveDataSource != null) {
        NutDaoRunner runner = new NutDaoRunner();
        runner.setSlaveDataSource(slaveDataSource);
        nutDao.setRunner(runner);
      }
      // 加入到ioc对象
      ioc.addBean(name + "Dao", nutDao);
    }
  }
}

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

private void injectManyDao() {
  // 正则匹配多数据库url
  String regex = "jdbc\\.many\\.(\\w*)\\.url";
  for (String key : conf.getKeys()) {
    Pattern pattern = Regex.getPattern(regex);
    Matcher match = pattern.matcher(key);
    if(match.find()) {
      // 获取数据库名称
      String name = match.group(1);
      String prefix_name = "jdbc.many." + name + ".";
      DataSource manyDataSource = DataSourceStarter.createManyDataSource(ioc, conf, prefix_name);
      NutDao nutDao = new NutDao();
      nutDao.setDataSource(manyDataSource);
      // 处理对应的从库
      String slave_prefix = prefix_name + "slave.";
      DataSource slaveDataSource = DataSourceStarter.getManySlaveDataSource(ioc, conf, slave_prefix);
      if(slaveDataSource != null) {
        NutDaoRunner runner = new NutDaoRunner();
        runner.setSlaveDataSource(slaveDataSource);
        nutDao.setRunner(runner);
      }
      // 加入到ioc对象
      ioc.addBean(name + "Dao", nutDao);
    }
  }
}

相关文章