@SuppressWarnings({ "unchecked", "rawtypes" }) private Collection<WebServerFactoryCustomizer<?>> getWebServerFactoryCustomizerBeans() { return (Collection) this.beanFactory .getBeansOfType(WebServerFactoryCustomizer.class, false, false).values(); }
/** * Return a single bean of the given type or subtypes, not looking in ancestor * factories. Useful convenience method when we expect a single bean and * don't care about the bean name. * <p>Does consider objects created by FactoryBeans, which means that FactoryBeans * will get initialized. If the object created by the FactoryBean doesn't match, * the raw FactoryBean itself will be matched against the type. * <p>This version of {@code beanOfType} automatically includes * prototypes and FactoryBeans. * @param lbf the bean factory * @param type type of bean to match * @return the matching bean instance * @throws NoSuchBeanDefinitionException if no bean of the given type was found * @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found * @throws BeansException if the bean could not be created * @see ListableBeanFactory#getBeansOfType(Class) */ public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException { Assert.notNull(lbf, "ListableBeanFactory must not be null"); Map<String, T> beansOfType = lbf.getBeansOfType(type); return uniqueBean(type, beansOfType); }
Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit); return uniqueBean(type, beansOfType);
private Collection<ErrorPageRegistrar> getRegistrars() { if (this.registrars == null) { // Look up does not include the parent context this.registrars = new ArrayList<>(this.beanFactory .getBeansOfType(ErrorPageRegistrar.class, false, false).values()); this.registrars.sort(AnnotationAwareOrderComparator.INSTANCE); this.registrars = Collections.unmodifiableList(this.registrars); } return this.registrars; }
/** * Gets bean configuration. * * @param ctx Spring context. * @param beanCls Bean class. * @return Spring bean. */ @Nullable private static <T> T bean(ListableBeanFactory ctx, Class<T> beanCls) { Map.Entry<String, T> entry = F.firstEntry(ctx.getBeansOfType(beanCls)); return entry == null ? null : entry.getValue(); }
/** * Return a single bean of the given type or subtypes, not looking in ancestor * factories. Useful convenience method when we expect a single bean and * don't care about the bean name. * <p>Does consider objects created by FactoryBeans, which means that FactoryBeans * will get initialized. If the object created by the FactoryBean doesn't match, * the raw FactoryBean itself will be matched against the type. * <p>This version of {@code beanOfType} automatically includes * prototypes and FactoryBeans. * @param lbf the bean factory * @param type type of bean to match * @return the matching bean instance * @throws NoSuchBeanDefinitionException if no bean of the given type was found * @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found * @throws BeansException if the bean could not be created * @see ListableBeanFactory#getBeansOfType(Class) */ public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException { Assert.notNull(lbf, "ListableBeanFactory must not be null"); Map<String, T> beansOfType = lbf.getBeansOfType(type); return uniqueBean(type, beansOfType); }
@Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { if (this.beanFactory instanceof ListableBeanFactory && getClass() == TypeExcludeFilter.class) { Collection<TypeExcludeFilter> delegates = ((ListableBeanFactory) this.beanFactory) .getBeansOfType(TypeExcludeFilter.class).values(); for (TypeExcludeFilter delegate : delegates) { if (delegate.match(metadataReader, metadataReaderFactory)) { return true; } } } return false; }
result.putAll(lbf.getBeansOfType(type)); if (lbf instanceof HierarchicalBeanFactory) { HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit); return uniqueBean(type, beansOfType);
result.putAll(lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit)); if (lbf instanceof HierarchicalBeanFactory) { HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
private Map<String, ?> getBeansOfType(Class<?> type) { Map<String, ?> beans = beanFactory.getBeansOfType(type); // Check ancestor bean factories if they exist and the current one has none of the // required type BeanFactory parent = beanFactory.getParentBeanFactory(); while (parent != null && beans.size() == 0) { if (parent instanceof ListableBeanFactory) { beans = ((ListableBeanFactory) parent).getBeansOfType(type); } if (parent instanceof HierarchicalBeanFactory) { parent = ((HierarchicalBeanFactory) parent).getParentBeanFactory(); } else { break; } } return beans; }
((ListableBeanFactory) this.beanFactory).getBeansOfType(JmsListenerConfigurer.class); List<JmsListenerConfigurer> configurers = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(configurers);
result.putAll(lbf.getBeansOfType(type)); if (lbf instanceof HierarchicalBeanFactory) { HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
result.putAll(lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit)); if (lbf instanceof HierarchicalBeanFactory) { HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
public static void removeEventListener(ListableBeanFactory applicationContext, ApplicationListener listener) { Map<String, ApplicationEventMulticaster> multicasters = applicationContext.getBeansOfType(ApplicationEventMulticaster.class); for (Map.Entry<String, ApplicationEventMulticaster> entry : multicasters.entrySet()) { entry.getValue().removeApplicationListener(listener); } }
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class); List<SchedulingConfigurer> configurers = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(configurers);
this.beanFactory.getBeansOfType(mapValue.getClass(), false, this.allowEagerInit); for (Map.Entry<String, ?> entry : beansOfSameType.entrySet()) { if (entry.getValue() == mapValue) {
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class); List<SchedulingConfigurer> configurers = new ArrayList<>(beans.values()); AnnotationAwareOrderComparator.sort(configurers);
/** * Starts new grid node. * * @param igniteInstanceName name of new node. * @param springCfg file with spring configuration to use for this node. * @return a grid instance local to new node {@link org.apache.ignite.Ignition#start(org.apache.ignite.configuration.IgniteConfiguration)}. * @throws Exception if node run failed. */ protected Ignite startNode(String igniteInstanceName, File springCfg) throws Exception { assert springCfg != null; ListableBeanFactory springCtx = new FileSystemXmlApplicationContext( "file:///" + springCfg.getAbsolutePath()); Map cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); assert cfgMap != null; assert !cfgMap.isEmpty(); IgniteConfiguration cfg = (IgniteConfiguration)cfgMap.values().iterator().next(); cfg.setIgniteInstanceName(igniteInstanceName + "-" + getNextNodeNum()); return G.start(cfg); } }
assertEquals(null, tb4.getName()); Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false); assertEquals(5, drs.size()); assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#0"));