List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory addEmbeddedValueResolver
void addEmbeddedValueResolver(StringValueResolver valueResolver);
From source file:io.neba.core.spring.applicationcontext.configuration.PlaceholderVariableResolverRegistrar.java
public void registerResolvers(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) { this.logger.info("Detecting " + PlaceholderVariableResolver.class + " instances in " + displayNameOf(bundleContext.getBundle()) + "..."); String[] valueResolvers = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, PlaceholderVariableResolver.class); for (String resolverName : valueResolvers) { StringValueResolver embeddableResolver = new PlaceholderVariableResolverWrapper(beanFactory, resolverName);/*from ww w.ja v a 2 s.c o m*/ beanFactory.addEmbeddedValueResolver(embeddableResolver); } this.logger.info("Detected and registered " + valueResolvers.length + " resolver(s)."); }
From source file:org.brekka.stillingar.spring.pc.ConfigurationPlaceholderConfigurer.java
/** * Copied in its entirety from the {@link PropertyPlaceholderConfigurer} method of the same name. The only changes * are to the valueResolver and BeanDefinitionVisitor instances. *///w w w . j a v a 2 s .c o m @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactoryToProcess) throws BeansException { String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); for (String curName : beanNames) { CustomStringValueResolver valueResolver = new CustomStringValueResolver(this.placeholderParser, this.configurationSource, this.beanFactory); // 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))) { BeanDefinition beanDef = beanFactoryToProcess.getBeanDefinition(curName); try { BeanDefinitionVisitor visitor = new CustomBeanDefinitionVisitor(curName, beanDef.isSingleton(), valueResolver); visitor.visitBeanDefinition(beanDef); } catch (Exception ex) { throw new BeanDefinitionStoreException(beanDef.getResourceDescription(), curName, ex); } } } StringValueResolver valueResolver = new CustomStringValueResolver(this.placeholderParser, this.configurationSource, this.beanFactory); // 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:de.acosix.alfresco.mtsupport.repo.subsystems.TenantAwareSubsystemPlaceholderConfigurer.java
/** * {@inheritDoc}/*from ww w. java 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.springframework.context.support.AbstractApplicationContext.java
/** * Finish the initialization of this context's bean factory, * initializing all remaining singleton beans. *//*w w w . j a v a 2s .c o m*/ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); } // Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); } // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); } // Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration(); // Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }