use of org.springframework.util.StringValueResolver in project spring-framework by spring-projects.
the class AbstractApplicationContext method finishBeanFactoryInitialization.
/**
* Finish the initialization of this context's bean factory,
* initializing all remaining singleton beans.
*/
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));
}
// at this point, primarily for resolution in annotation attribute values.
if (!beanFactory.hasEmbeddedValueResolver()) {
beanFactory.addEmbeddedValueResolver(new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
return 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();
}
use of org.springframework.util.StringValueResolver in project hale by halestudio.
the class ConfigurationServicePlaceholderConfigurer method processProperties.
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver();
this.doProcessProperties(beanFactory, valueResolver);
}
use of org.springframework.util.StringValueResolver in project incubator-servicecomb-java-chassis by apache.
the class TestSwaggerGenerator method testBasePathPlaceHolder.
@Test
public void testBasePathPlaceHolder() {
StringValueResolver stringValueResolver = SpringUtils.createStringValueResolver(Collections.singletonMap("var", "varValue"));
PojoSwaggerGeneratorContext context = new PojoSwaggerGeneratorContext();
context.setEmbeddedValueResolver(stringValueResolver);
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(context, null);
swaggerGenerator.setBasePath("/a/${var}/b");
Assert.assertEquals("/a/varValue/b", swaggerGenerator.getSwagger().getBasePath());
}
use of org.springframework.util.StringValueResolver in project disconf by knightliao.
the class ReloadingPropertyPlaceholderConfigurer method processProperties.
/**
* copy & paste, just so we can insert our own visitor.
* 启动时 进行配置的解析
*/
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
BeanDefinitionVisitor visitor = new ReloadingPropertyPlaceholderConfigurer.PlaceholderResolvingBeanDefinitionVisitor(props);
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
// .unicon.iamlabs.spring.properties file locations.
if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
this.currentBeanName = beanNames[i];
try {
BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
try {
visitor.visitBeanDefinition(bd);
} catch (BeanDefinitionStoreException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
}
} finally {
currentBeanName = null;
}
}
}
StringValueResolver stringValueResolver = new PlaceholderResolvingStringValueResolver(props);
// New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
beanFactoryToProcess.resolveAliases(stringValueResolver);
// New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
beanFactoryToProcess.addEmbeddedValueResolver(stringValueResolver);
}
use of org.springframework.util.StringValueResolver in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method resolveEmbeddedValue.
@Test
void resolveEmbeddedValue() {
StringValueResolver r1 = mock(StringValueResolver.class);
StringValueResolver r2 = mock(StringValueResolver.class);
StringValueResolver r3 = mock(StringValueResolver.class);
lbf.addEmbeddedValueResolver(r1);
lbf.addEmbeddedValueResolver(r2);
lbf.addEmbeddedValueResolver(r3);
given(r1.resolveStringValue("A")).willReturn("B");
given(r2.resolveStringValue("B")).willReturn(null);
given(r3.resolveStringValue(isNull())).willThrow(new IllegalArgumentException());
lbf.resolveEmbeddedValue("A");
verify(r1).resolveStringValue("A");
verify(r2).resolveStringValue("B");
verify(r3, never()).resolveStringValue(isNull());
}
Aggregations