List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanDefinitionNames
String[] getBeanDefinitionNames();
From source file:com.photon.phresco.configuration.XmlPropertyPlaceholderConfigurer.java
@Override protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException { org.springframework.util.StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver( props);// ww w. ja va2s. co m org.springframework.beans.factory.config.BeanDefinitionVisitor visitor = new org.springframework.beans.factory.config.BeanDefinitionVisitor( valueResolver); String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); for (int i = 0; i < beanNames.length; i++) { // Check that we're not parsing our own bean definition, // to avoid failing on unresolvable placeholders in properties file locations. if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) { BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]); try { visitor.visitBeanDefinition(bd); } catch (BeanDefinitionStoreException ex) { throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage()); } } } // New in Spring 2.5: resolve placeholders in alias target names and aliases as well. beanFactoryToProcess.resolveAliases(valueResolver); }
From source file:org.activiti.spring.components.scope.ProcessScope.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { beanFactory.registerScope(ProcessScope.PROCESS_SCOPE_NAME, this); Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, "BeanFactory was not a BeanDefinitionRegistry, so ProcessScope cannot be used."); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition definition = beanFactory.getBeanDefinition(beanName); // Replace this or any of its inner beans with scoped proxy if it has this scope boolean scoped = PROCESS_SCOPE_NAME.equals(definition.getScope()); Scopifier scopifier = new Scopifier(registry, PROCESS_SCOPE_NAME, proxyTargetClass, scoped); scopifier.visitBeanDefinition(definition); if (scoped) { Scopifier.createScopedProxy(beanName, definition, registry, proxyTargetClass); }// www . j a v a 2 s . c om } beanFactory.registerSingleton(ProcessScope.PROCESS_SCOPE_PROCESS_VARIABLES_SINGLETON, this.processVariablesMap); beanFactory.registerResolvableDependency(ProcessInstance.class, createSharedProcessInstance()); }
From source file:org.solmix.runtime.support.spring.ContainerPostProcessor.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Object inject = container;/* w w w . j a va2s .c om*/ if (inject == null) { inject = getContainerByName(Container.DEFAULT_CONTAINER_ID, beanFactory, true, null); } else { if (!beanFactory.containsBeanDefinition(Container.DEFAULT_CONTAINER_ID) && !beanFactory.containsSingleton(Container.DEFAULT_CONTAINER_ID)) { beanFactory.registerSingleton(Container.DEFAULT_CONTAINER_ID, container); } } for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); Object p = beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_ATTRIBUTE); if (p == null) continue; String name = (String) beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_NAME); String create = (String) beanDefinition .getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_CREATE); Object inj = inject; if (name != null) { if (container != null) { continue; } inj = getContainerByName(name, beanFactory, create != null, create); } beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_NAME); beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_ATTRIBUTE); beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_CREATE); if (create == null) { if (Boolean.valueOf(p.toString())) { beanDefinition.getPropertyValues().addPropertyValue("container", inj); } else { ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues(); insertConstructorArg(constructorArgs, inj); } } } //end loop bean. }
From source file:org.constretto.spring.EnvironmentAnnotationConfigurer.java
@SuppressWarnings("unchecked") public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { if (!(configurableListableBeanFactory instanceof DefaultListableBeanFactory)) { throw new IllegalStateException( "EnvironmentAnnotationConfigurer needs to operate on a DefaultListableBeanFactory"); }/*from ww w . j a va 2 s .co m*/ DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableListableBeanFactory; defaultListableBeanFactory.setAutowireCandidateResolver(new ConstrettoAutowireCandidateResolver()); String[] beanNames = configurableListableBeanFactory.getBeanDefinitionNames(); int lowestDiscoveredPriority = Integer.MAX_VALUE; for (String beanName : beanNames) { BeanDefinition beanDefinition = configurableListableBeanFactory.getBeanDefinition(beanName); if (beanDefinition.getBeanClassName() != null) { try { Class beanClass = Class.forName(beanDefinition.getBeanClassName()); Environment environmentAnnotation = findEnvironmentAnnotation(beanClass); if (environmentAnnotation != null) { if (!assemblyContextResolver.getAssemblyContext().isEmpty()) { boolean autowireCandidate = decideIfAutowireCandiate(beanName, environmentAnnotation); beanDefinition.setAutowireCandidate(autowireCandidate); if (autowireCandidate) { removeNonAnnotatedBeansFromAutowireForType(beanClass, configurableListableBeanFactory); } } else { beanDefinition.setAutowireCandidate(false); } } } catch (ClassNotFoundException e) { beanDefinition.setAutowireCandidate(false); } } } }
From source file:org.everrest.spring.SpringComponentsLoader.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { beanFactory.registerSingleton("org.everrest.lifecycle.SpringEverrestProcessorLifecycle", new SpringEverrestProcessorLifecycle(processor)); beanFactory.registerSingleton("org.everrest.lifecycle.SpringFileCollectorDestroyer", new SpringFileCollectorDestroyer(makeFileCollectorDestroyer())); EverrestApplication everrest = makeEverrestApplication(); ResourceDescriptorValidator rdv = ResourceDescriptorValidator.getInstance(); addAutowiredDependencies(beanFactory); for (String beanName : beanFactory.getBeanDefinitionNames()) { Class<?> beanClass = beanFactory.getType(beanName); if (beanClass.getAnnotation(Provider.class) != null) { ProviderDescriptor pDescriptor = new ProviderDescriptorImpl(beanClass); pDescriptor.accept(rdv);/*from w w w . ja v a 2s .co m*/ everrest.addFactory(new SpringObjectFactory<>(pDescriptor, beanName, beanFactory)); } else if (beanClass.getAnnotation(Filter.class) != null) { FilterDescriptor fDescriptor = new FilterDescriptorImpl(beanClass); fDescriptor.accept(rdv); everrest.addFactory(new SpringObjectFactory<>(fDescriptor, beanName, beanFactory)); } else if (beanClass.getAnnotation(Path.class) != null) { AbstractResourceDescriptor rDescriptor = new AbstractResourceDescriptorImpl(beanClass); rDescriptor.accept(rdv); everrest.addFactory(new SpringObjectFactory<>(rDescriptor, beanName, beanFactory)); } } processor.addApplication(everrest); }
From source file:org.bytesoft.bytetcc.supports.dubbo.DubboConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); List<BeanDefinition> appNameList = new ArrayList<BeanDefinition>(); List<BeanDefinition> providerList = new ArrayList<BeanDefinition>(); List<BeanDefinition> consumerList = new ArrayList<BeanDefinition>(); List<BeanDefinition> protocolList = new ArrayList<BeanDefinition>(); List<BeanDefinition> registryList = new ArrayList<BeanDefinition>(); Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>(); Map<String, BeanDefinition> referenceMap = new HashMap<String, BeanDefinition>(); Map<String, Class<?>> clazzMap = new HashMap<String, Class<?>>(); Map<String, BeanDefinition> compensableMap = new HashMap<String, BeanDefinition>(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = null; try {/*w w w. j a v a2 s . co m*/ beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { logger.warn("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex); continue; } clazzMap.put(beanClassName, beanClass); if (beanClass.getAnnotation(Compensable.class) != null) { compensableMap.put(beanName, beanDef); } } for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = clazzMap.get(beanClassName); if (com.alibaba.dubbo.config.ApplicationConfig.class.equals(beanClass)) { appNameList.add(beanDef); } else if (com.alibaba.dubbo.config.ProtocolConfig.class.equals(beanClass)) { protocolList.add(beanDef); } else if (com.alibaba.dubbo.config.RegistryConfig.class.equals(beanClass)) { registryList.add(beanDef); } else if (com.alibaba.dubbo.config.ProviderConfig.class.equals(beanClass)) { providerList.add(beanDef); } else if (com.alibaba.dubbo.config.ConsumerConfig.class.equals(beanClass)) { consumerList.add(beanDef); } else if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue ref = mpv.getPropertyValue("ref"); RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue(); String refBeanName = beanRef.getBeanName(); if (compensableMap.containsKey(refBeanName) == false) { continue; } serviceMap.put(beanName, beanDef); } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue group = mpv.getPropertyValue("group"); if (group == null || group.getValue() == null || "org.bytesoft.bytetcc".equals(group.getValue()) == false) { continue; } referenceMap.put(beanName, beanDef); } } Set<BeanDefinition> providerSet = new HashSet<BeanDefinition>(); Set<BeanDefinition> protocolSet = new HashSet<BeanDefinition>(); for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue provider = mpv.getPropertyValue("provider"); PropertyValue protocol = mpv.getPropertyValue("protocol"); String providerValue = provider == null ? null : String.valueOf(provider.getValue()); if (providerValue == null) { if (providerList.size() > 0) { providerSet.add(providerList.get(0)); } } else if ("N/A".equals(providerValue) == false) { String[] keyArray = providerValue.split("\\s*,\\s*"); for (int j = 0; j < keyArray.length; j++) { String key = keyArray[j]; BeanDefinition def = beanFactory.getBeanDefinition(key); providerSet.add(def); } } String protocolValue = protocol == null ? null : String.valueOf(protocol.getValue()); if (protocolValue == null) { if (protocolList.size() > 0) { protocolSet.add(protocolList.get(0)); } } else if ("N/A".equals(protocolValue) == false) { String[] keyArray = protocolValue.split("\\s*,\\s*"); for (int i = 0; i < keyArray.length; i++) { String key = keyArray[i]; BeanDefinition def = beanFactory.getBeanDefinition(key); protocolSet.add(def); } } } ApplicationConfigValidator appConfigValidator = new ApplicationConfigValidator(); appConfigValidator.setDefinitionList(appNameList); appConfigValidator.validate(); if (protocolList.size() == 0) { throw new FatalBeanException("There is no protocol config specified!"); } for (Iterator<BeanDefinition> itr = protocolSet.iterator(); itr.hasNext();) { BeanDefinition beanDef = itr.next(); ProtocolConfigValidator validator = new ProtocolConfigValidator(); validator.setBeanDefinition(beanDef); validator.validate(); } for (Iterator<BeanDefinition> itr = providerSet.iterator(); itr.hasNext();) { BeanDefinition beanDef = itr.next(); ProviderConfigValidator validator = new ProviderConfigValidator(); validator.setBeanDefinition(beanDef); validator.validate(); } for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); ServiceConfigValidator validator = new ServiceConfigValidator(); validator.setBeanName(entry.getKey()); validator.setBeanDefinition(entry.getValue()); validator.validate(); // retries, loadbalance, cluster, filter, group } for (Iterator<Map.Entry<String, BeanDefinition>> itr = referenceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); ReferenceConfigValidator validator = new ReferenceConfigValidator(); validator.setBeanName(entry.getKey()); validator.setBeanDefinition(entry.getValue()); validator.validate(); // retries, loadbalance, cluster, filter } }
From source file:de.acosix.alfresco.mtsupport.repo.subsystems.TenantAwareSubsystemPlaceholderConfigurer.java
/** * {@inheritDoc}/* w ww .j a v a 2s .c om*/ */ @Override protected void doProcessProperties(final ConfigurableListableBeanFactory beanFactoryToProcess, final StringValueResolver valueResolver) { final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) { /** * {@inheritDoc} */ @Override protected Object resolveValue(final Object value) { Object result = value; // TODO Report bug with Spring // TypedStringValue may be reused as result of cloneBeanDefinition and thus should not be mutated if (value instanceof TypedStringValue) { final TypedStringValue typedStringValue = (TypedStringValue) value; final String stringValue = typedStringValue.getValue(); if (stringValue != null) { final String visitedString = this.resolveStringValue(stringValue); if (!stringValue.equals(visitedString)) { result = typedStringValue.hasTargetType() ? new TypedStringValue(visitedString, typedStringValue.getTargetType()) : new TypedStringValue(visitedString); } } } else { result = super.resolveValue(value); } return result; } }; final String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); for (final String curName : beanNames) { // Check that we're not parsing our own bean definition, // to avoid failing on unresolvable placeholders in properties file locations. if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) { final String tenantDomain; if (curName.contains(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN)) { tenantDomain = curName.substring(curName.indexOf(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN) + TenantBeanUtils.TENANT_BEAN_NAME_PATTERN.length()); LOGGER.debug("[{}] Processing bean {} for tenant domain {}", this.beanName, curName, tenantDomain); } else { LOGGER.debug("[{}] Processing bean {} without tenant domain", this.beanName, curName); tenantDomain = null; } final BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName); TENANT_CONTEXT.set(tenantDomain); try { visitor.visitBeanDefinition(bd); } catch (final Exception ex) { throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage()); } finally { TENANT_CONTEXT.remove(); } } } LOGGER.debug("[{}] Completed processing all beans", this.beanName); // New in Spring 2.5: resolve placeholders in alias target names and aliases as well. beanFactoryToProcess.resolveAliases(valueResolver); // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes. beanFactoryToProcess.addEmbeddedValueResolver(valueResolver); }
From source file:org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.java
/** * Prepares Spring context.//w ww .ja v a 2 s . c o m * * @param excludedProps Properties to be excluded. * @return application context. */ private static GenericApplicationContext prepareSpringContext(final String... excludedProps) { GenericApplicationContext springCtx = new GenericApplicationContext(); if (excludedProps.length > 0) { final List<String> excludedPropsList = Arrays.asList(excludedProps); BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() { /** * @param def Registered BeanDefinition. * @throws BeansException in case of errors. */ private void processNested(BeanDefinition def) throws BeansException { Iterator<PropertyValue> iterVals = def.getPropertyValues().getPropertyValueList().iterator(); while (iterVals.hasNext()) { PropertyValue val = iterVals.next(); if (excludedPropsList.contains(val.getName())) { iterVals.remove(); continue; } if (val.getValue() instanceof Iterable) { Iterator iterNested = ((Iterable) val.getValue()).iterator(); while (iterNested.hasNext()) { Object item = iterNested.next(); if (item instanceof BeanDefinitionHolder) { BeanDefinitionHolder h = (BeanDefinitionHolder) item; try { if (h.getBeanDefinition().getBeanClassName() != null) Class.forName(h.getBeanDefinition().getBeanClassName()); processNested(h.getBeanDefinition()); } catch (ClassNotFoundException ignored) { iterNested.remove(); } } } } } } @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { for (String beanName : beanFactory.getBeanDefinitionNames()) { try { BeanDefinition def = beanFactory.getBeanDefinition(beanName); if (def.getBeanClassName() != null) Class.forName(def.getBeanClassName()); processNested(def); } catch (ClassNotFoundException ignored) { ((BeanDefinitionRegistry) beanFactory).removeBeanDefinition(beanName); } } } }; springCtx.addBeanFactoryPostProcessor(postProc); } return springCtx; }
From source file:org.bytesoft.bytejta.supports.springcloud.SpringCloudConfiguration.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; }/* w ww . j ava 2 s. co m*/ MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }