@Test public void individualBeanWithNullReturningSupplier() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("a", BeanA.class, () -> null); context.registerBean("b", BeanB.class, BeanB::new); context.registerBean("c", BeanC.class, BeanC::new); context.refresh(); assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanA.class), "a")); assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanB.class), "b")); assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c")); assertTrue(context.getBeansOfType(BeanA.class).isEmpty()); assertSame(context.getBean(BeanB.class), context.getBeansOfType(BeanB.class).values().iterator().next()); assertSame(context.getBean(BeanC.class), context.getBeansOfType(BeanC.class).values().iterator().next()); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { store = store(); URL cfgUrl; try { cfgUrl = new URL(DFLT_MAPPING_CONFIG); } catch (MalformedURLException ignore) { cfgUrl = U.resolveIgniteUrl(DFLT_MAPPING_CONFIG); } if (cfgUrl == null) throw new Exception("Failed to resolve metadata path: " + DFLT_MAPPING_CONFIG); try { GenericApplicationContext springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); Collection<JdbcType> types = new ArrayList<>(springCtx.getBeansOfType(JdbcType.class).values()); store.setTypes(types.toArray(new JdbcType[types.size()])); } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + "[springUrl=" + cfgUrl + ']', e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + cfgUrl + ", err=" + e.getMessage() + ']', e); } }
@Override public <T> Map<String,T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException { return m_moduleContext.getBeansOfType(type, includeNonSingletons, allowEagerInit); }
@Override public <T> Map<String,T> getBeansOfType(Class<T> type) throws BeansException { return m_moduleContext.getBeansOfType(type); }
@Override public <T> Map<String,T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException { return m_moduleContext.getBeansOfType(type, includeNonSingletons, allowEagerInit); }
@Override public <T> Map<String,T> getBeansOfType(Class<T> type) throws BeansException { return m_moduleContext.getBeansOfType(type); }
public <T> T getBeanOfType(Class<T> clazz) { Map<String, T> beans = applicationContext.getBeansOfType(clazz); if (beans.size() == 0) { return null; } return beans.values().iterator().next(); } }
public static <T> Map<String, T> getBeansOfType(Class type) { if (SpringPlugin.applicationContext == null) { throw new SpringException(); } return SpringPlugin.applicationContext.getBeansOfType(type); }
private Set<Rule> getRules() { final Collection<Rule> ruleCollection = getContext().getBeansOfType(Rule.class).values(); return Sets.newHashSet(ruleCollection); } }
@Override @SuppressWarnings("unchecked") public <T> T getBeanOfType(Class<T> type) { // XXX The map is not generic but we know it contains objects so this is safe Map<String, Object> beans = context.getBeansOfType(type); if (beans.size() == 1) return (T)beans.values().iterator().next(); if (beans.size() == 0) throw new MissingBeanException(type); throw new NonUniqueBeanException(beans.size(), beans.keySet(), type); }
public EnableWebFluxConfigurationWrapper(GenericApplicationContext context, WebFluxProperties webFluxProperties) { super(webFluxProperties, context.getBeanProvider(WebFluxRegistrations.class)); setConfigurers(new ArrayList<>(context.getBeansOfType(WebFluxConfigurer.class).values())); }
public void execute() throws MojoExecutionException, MojoFailureException { init(); Collection<AbstractRule> rules = getContext().getBeansOfType(AbstractRule.class).values(); Map<String, AbstractRule> name2ruleMap = Maps.newTreeMap(); for (AbstractRule rule : rules) { name2ruleMap.put(rule.getIdentifier(), rule); } StringBuilder buffer = new StringBuilder(); for (Map.Entry<String, AbstractRule> entry : name2ruleMap.entrySet()) { AbstractRule rule = entry.getValue(); buffer. append("- "). append(rule.getIdentifier()). append("\n\n"). append(formatAsBlock(rule)). append("\n\n"); } System.out.println(buffer.toString().replaceFirst("\n$", "")); }
@SuppressWarnings("rawtypes") private Collection<Tuple3<TurboService, Class, Object>> getTurboServiceList() { Map<String, Object> beans = applicationContext.getBeansOfType(Object.class);
@Override public void initialize(GenericApplicationContext context) { context.registerBean(WebClient.Builder.class, () -> new WebClientAutoConfiguration(context.getBeanProvider(WebClientCustomizer.class)).webClientBuilder()); context.registerBean(DefaultWebClientCodecCustomizer.class, () -> new DefaultWebClientCodecCustomizer(this.baseUrl, new ArrayList<>(context.getBeansOfType(CodecCustomizer.class).values()))); }
= applicationContext.getBeansOfType(TurboServerAware.class);
private void registerGsonAutoConfiguration() { GsonAutoConfiguration config = new GsonAutoConfiguration(); context.registerBean(GsonBuilder.class, () -> config.gsonBuilder(new ArrayList<>( context.getBeansOfType(GsonBuilderCustomizer.class).values()))); context.registerBean(Gson.class, () -> config.gson(context.getBean(GsonBuilder.class))); context.registerBean(GsonBuilderCustomizer.class, () -> config .standardGsonBuilderCustomizer(context.getBean(GsonProperties.class))); }
private void registerGsonAutoConfiguration() { GsonAutoConfiguration config = new GsonAutoConfiguration(); context.registerBean(GsonBuilder.class, () -> config.gsonBuilder(new ArrayList<>( context.getBeansOfType(GsonBuilderCustomizer.class).values()))); context.registerBean(Gson.class, () -> config.gson(context.getBean(GsonBuilder.class))); context.registerBean(GsonBuilderCustomizer.class, () -> config .standardGsonBuilderCustomizer(context.getBean(GsonProperties.class))); }
@Override public void initialize(GenericApplicationContext context) { context.registerBean(Jackson2ObjectMapperBuilderCustomizer.class, () -> new Jackson2ObjectMapperBuilderCustomizerConfiguration().standardJacksonObjectMapperBuilderCustomizer(context, this.properties)); context.registerBean(Jackson2ObjectMapperBuilder.class, () -> new JacksonObjectMapperBuilderConfiguration(context).jacksonObjectMapperBuilder(new ArrayList<>(context.getBeansOfType(Jackson2ObjectMapperBuilderCustomizer.class).values()))); context.registerBean(ObjectMapper.class, () -> new JacksonObjectMapperConfiguration().jacksonObjectMapper(context.getBean(Jackson2ObjectMapperBuilder.class))); } }
final Map<String, ?> beans = appContext.getBeansOfType(descriptor.getPropertyType());