Java Code Examples for org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getParentBeanFactory()
The following examples show how to use
org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getParentBeanFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnableConfigurationPropertiesImportSelector.java From spring-cloud-gray with Apache License 2.0 | 5 votes |
private boolean containsBeanDefinition( ConfigurableListableBeanFactory beanFactory, String name) { if (beanFactory.containsBeanDefinition(name)) { return true; } BeanFactory parent = beanFactory.getParentBeanFactory(); if (parent instanceof ConfigurableListableBeanFactory) { return containsBeanDefinition((ConfigurableListableBeanFactory) parent, name); } return false; }
Example 2
Source File: Bulbasaur.java From bulbasaur with Apache License 2.0 | 5 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (springContextShare) { if (beanFactory.getParentBeanFactory() == null) { beanFactory.setParentBeanFactory(innerBeanFactory); } else { logger.warn("Had set Parent applicationContext!"); } } }
Example 3
Source File: LocalFeignBeanDefinitionRegistryPostProcessor.java From onetwo with Apache License 2.0 | 5 votes |
protected void modifyFeignBeanFacotries(ConfigurableListableBeanFactory beanFactory){ ListableBeanFactory bf = (ListableBeanFactory)beanFactory.getParentBeanFactory(); if(bf==null){ return ; } String[] feignBeanNames = bf.getBeanNamesForAnnotation(EnhanceFeignClient.class); BeanDefinitionRegistry bdr = (BeanDefinitionRegistry)bf; Stream.of(feignBeanNames).forEach(beanName->{ BeanDefinition feignBeanDefinition = bdr.getBeanDefinition(feignBeanNames[0]); String typeName = (String)feignBeanDefinition.getPropertyValues().getPropertyValue("type").getValue(); Class<?> fallbackType = (Class<?>)feignBeanDefinition.getPropertyValues().getPropertyValue("fallback").getValue(); Class<?> clientInterface = ReflectUtils.loadClass(typeName); Class<?> apiInterface = clientInterface.getInterfaces()[0]; String[] typeBeanNames = bf.getBeanNamesForType(apiInterface);//maybe: feignclient, fallback, controller if(typeBeanNames.length<=1){ return ; } String[] localBeanNames = ArrayUtils.removeElement(typeBeanNames, beanName);//remove Optional<String> localBeanNameOpt = Stream.of(localBeanNames).filter(lbn->{ BeanDefinition bd = bdr.getBeanDefinition(lbn); return !bd.getBeanClassName().equals(fallbackType.getName()); }) .findFirst(); if(!localBeanNameOpt.isPresent()){ return ; } MutablePropertyValues mpvs = feignBeanDefinition.getPropertyValues(); this.clearMutablePropertyValues(mpvs); feignBeanDefinition.setBeanClassName(LocalFeignInvokerFactoryBean.class.getName()); mpvs.addPropertyValue("remoteInterface", clientInterface); mpvs.addPropertyValue("localBeanName", localBeanNameOpt.get()); }); }
Example 4
Source File: MongoDbFactoryDependsOnPostProcessor.java From mongeez-spring-boot-starter with Apache License 2.0 | 5 votes |
private static BeanDefinition getBeanDefinition(String beanName, ConfigurableListableBeanFactory beanFactory) { try { return beanFactory.getBeanDefinition(beanName); } catch (NoSuchBeanDefinitionException ex) { BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory instanceof ConfigurableListableBeanFactory) { return getBeanDefinition(beanName, (ConfigurableListableBeanFactory) parentBeanFactory); } throw ex; } }
Example 5
Source File: AutoJsonRpcServiceImplExporter.java From jsonrpc4j with MIT License | 5 votes |
@SuppressWarnings("Convert2streamapi") private static void collectFromParentBeans(ConfigurableListableBeanFactory beanFactory, Map<String, String> serviceBeanNames) { BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) { for (Entry<String, String> entry : findServiceBeanDefinitions((ConfigurableListableBeanFactory) parentBeanFactory).entrySet()) { if (isNotDuplicateService(serviceBeanNames, entry.getKey(), entry.getValue())) { serviceBeanNames.put(entry.getKey(), entry.getValue()); } } } }
Example 6
Source File: AutoJsonRpcServiceImplExporter.java From jsonrpc4j with MIT License | 5 votes |
/** * Find a {@link BeanDefinition} in the {@link BeanFactory} or it's parents. */ private BeanDefinition findBeanDefinition(ConfigurableListableBeanFactory beanFactory, String serviceBeanName) { if (beanFactory.containsLocalBean(serviceBeanName)) { return beanFactory.getBeanDefinition(serviceBeanName); } BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) { return findBeanDefinition((ConfigurableListableBeanFactory) parentBeanFactory, serviceBeanName); } throw new NoSuchBeanDefinitionException(serviceBeanName); }
Example 7
Source File: AutoJsonRpcServiceExporter.java From jsonrpc4j with MIT License | 5 votes |
@SuppressWarnings("Convert2streamapi") private static void collectFromParentBeans(ConfigurableListableBeanFactory beanFactory, Map<String, String> serviceBeanNames) { BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) { for (Entry<String, String> entry : findServiceBeanDefinitions((ConfigurableListableBeanFactory) parentBeanFactory).entrySet()) { if (isNotDuplicateService(serviceBeanNames, entry.getKey(), entry.getValue())) serviceBeanNames.put(entry.getKey(), entry.getValue()); } } }
Example 8
Source File: AutoJsonRpcServiceExporter.java From jsonrpc4j with MIT License | 5 votes |
/** * Find a {@link BeanDefinition} in the {@link BeanFactory} or it's parents. */ private BeanDefinition findBeanDefinition(ConfigurableListableBeanFactory beanFactory, String serviceBeanName) { if (beanFactory.containsLocalBean(serviceBeanName)) return beanFactory.getBeanDefinition(serviceBeanName); BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) return findBeanDefinition((ConfigurableListableBeanFactory) parentBeanFactory, serviceBeanName); throw new RuntimeException(format("Bean with name '%s' can no longer be found.", serviceBeanName)); }
Example 9
Source File: BeanUtils.java From spring-context-support with Apache License 2.0 | 3 votes |
/** * Get Bean Names from {@link ConfigurableListableBeanFactory} by type. * * @param beanFactory {@link ConfigurableListableBeanFactory} * @param beanClass The {@link Class} of Bean * @param includingAncestors including ancestors or not * @return If found , return the array of Bean Names , or empty array. */ public static String[] getBeanNames(ConfigurableListableBeanFactory beanFactory, Class<?> beanClass, boolean includingAncestors) { Set<String> beanNames = new LinkedHashSet<String>(); beanNames.addAll(doGetBeanNames(beanFactory, beanClass)); if (includingAncestors) { BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory instanceof ConfigurableListableBeanFactory) { ConfigurableListableBeanFactory configurableListableBeanFactory = (ConfigurableListableBeanFactory) parentBeanFactory; String[] parentBeanNames = getBeanNames(configurableListableBeanFactory, beanClass, includingAncestors); beanNames.addAll(Arrays.asList(parentBeanNames)); } } return StringUtils.toStringArray(beanNames); }