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

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

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

Ioc.getNamesByType介绍

暂无

代码示例

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

  1. names = ioc.getNamesByType(type);
  2. if (names != null && names.length == 1) {
  3. return ioc.get(type, names[0]);

代码示例来源: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/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. 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;

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

  1. for (String realmName : ioc.getNamesByType(Realm.class)) {
  2. AuthorizingRealm realm = ioc.get(AuthorizingRealm.class, realmName);
  3. if (conf.getBoolean(PROP_REALM_CACHE_ENABLE, false)) {

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

  1. public static DataSource createDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
  2. switch (conf.get(prefix + "type", "druid")) {
  3. case "simple":
  4. case "org.nutz.dao.impl.SimpleDataSource":
  5. SimpleDataSource simpleDataSource = new SimpleDataSource();
  6. String jdbcUrl = conf.get(PRE + "jdbcUrl", conf.get(PRE + "url"));
  7. if (Strings.isBlank(jdbcUrl)) {
  8. throw new RuntimeException("need " + PRE + ".url");
  9. }
  10. simpleDataSource.setJdbcUrl(jdbcUrl);
  11. simpleDataSource.setUsername(conf.get(PROP_USERNAME));
  12. simpleDataSource.setPassword(conf.get(PROP_PASSWORD));
  13. return simpleDataSource;
  14. case "druid":
  15. case "com.alibaba.druid.pool.DruidDataSource":
  16. DataSource ds = ioc.get(DataSource.class, "druidDataSource");
  17. String[] tmp = ioc.getNamesByType(DruidPasswordCallback.class);
  18. for (String beanName : tmp) {
  19. if (!Strings.isBlank(beanName))
  20. ((DruidDataSource)ds).setPasswordCallback(ioc.get(DruidPasswordCallback.class, beanName));
  21. }
  22. return ds;
  23. case "hikari":
  24. case "com.zaxxer.hikari.HikariDataSource":
  25. return ioc.get(DataSource.class, "hikariDataSource");
  26. default:
  27. break;
  28. }
  29. throw new RuntimeException("not supported jdbc.type=" + conf.get("jdbc.type"));
  30. }

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

  1. public static DataSource createDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
  2. switch (conf.get(prefix + "type", "druid")) {
  3. case "simple":
  4. case "org.nutz.dao.impl.SimpleDataSource":
  5. SimpleDataSource simpleDataSource = new SimpleDataSource();
  6. String jdbcUrl = conf.get(PRE + "jdbcUrl", conf.get(PRE + "url"));
  7. if (Strings.isBlank(jdbcUrl)) {
  8. throw new RuntimeException("need " + PRE + ".url");
  9. }
  10. simpleDataSource.setJdbcUrl(jdbcUrl);
  11. simpleDataSource.setUsername(conf.get(PROP_USERNAME));
  12. simpleDataSource.setPassword(conf.get(PROP_PASSWORD));
  13. return simpleDataSource;
  14. case "druid":
  15. case "com.alibaba.druid.pool.DruidDataSource":
  16. DataSource ds = ioc.get(DataSource.class, "druidDataSource");
  17. String[] tmp = ioc.getNamesByType(DruidPasswordCallback.class);
  18. for (String beanName : tmp) {
  19. if (!Strings.isBlank(beanName))
  20. ((DruidDataSource)ds).setPasswordCallback(ioc.get(DruidPasswordCallback.class, beanName));
  21. }
  22. return ds;
  23. case "hikari":
  24. case "com.zaxxer.hikari.HikariDataSource":
  25. return ioc.get(DataSource.class, "hikariDataSource");
  26. default:
  27. break;
  28. }
  29. throw new RuntimeException("not supported jdbc.type=" + conf.get("jdbc.type"));
  30. }

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

  1. names = ioc.getNamesByType(type);
  2. if (names != null && names.length == 1) {
  3. return ioc.get(type, names[0]);

相关文章