本文整理汇总了Java中org.springframework.util.StringValueResolver类的典型用法代码示例。如果您正苦于以下问题:Java StringValueResolver类的具体用法?Java StringValueResolver怎么用?Java StringValueResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringValueResolver类属于org.springframework.util包,在下文中一共展示了StringValueResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
*/
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
final ConfigurablePropertyResolver propertyResolver) throws BeansException {
propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
String resolved = ignoreUnresolvablePlaceholders ?
propertyResolver.resolvePlaceholders(strVal) :
propertyResolver.resolveRequiredPlaceholders(strVal);
return (resolved.equals(nullValue) ? null : resolved);
}
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
示例2: copyPropertiesToBean
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Copy the properties of the supplied {@link Annotation} to the supplied target bean.
* Any properties defined in {@code excludedProperties} will not be copied.
* <p>A specified value resolver may resolve placeholders in property values, for example.
* @param ann the annotation to copy from
* @param bean the bean instance to copy to
* @param valueResolver a resolve to post-process String property values (may be {@code null})
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
for (Method annotationProperty : annotationProperties) {
String propertyName = annotationProperty.getName();
if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) {
Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
if (valueResolver != null && value instanceof String) {
value = valueResolver.resolveStringValue((String) value);
}
bw.setPropertyValue(propertyName, value);
}
}
}
示例3: doProcessProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
StringValueResolver valueResolver) {
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
for (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))) {
BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
try {
visitor.visitBeanDefinition(bd);
}
catch (Exception ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage(), ex);
}
}
}
// 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);
}
示例4: setUp
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@Before
public void setUp() {
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
if ("${pattern}".equals(strVal)) {
return "#,##.00";
}
else {
return strVal;
}
}
});
conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
LocaleContextHolder.setLocale(Locale.US);
binder = new DataBinder(new TestBean());
binder.setConversionService(conversionService);
}
示例5: copyPropertiesToBean
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Copy the properties of the supplied {@link Annotation} to the supplied target bean.
* Any properties defined in {@code excludedProperties} will not be copied.
* <p>A specified value resolver may resolve placeholders in property values, for example.
* @param ann the annotation to copy from
* @param bean the bean instance to copy to
* @param valueResolver a resolve to post-process String property values (may be {@code null})
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
for (Method annotationProperty : annotationProperties) {
String propertyName = annotationProperty.getName();
if (!excluded.contains(propertyName) && bw.isWritableProperty(propertyName)) {
Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
if (valueResolver != null && value instanceof String) {
value = valueResolver.resolveStringValue((String) value);
}
bw.setPropertyValue(propertyName, value);
}
}
}
示例6: resolveEmbeddedValue
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@Test
public void resolveEmbeddedValue() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
StringValueResolver r1 = mock(StringValueResolver.class);
StringValueResolver r2 = mock(StringValueResolver.class);
StringValueResolver r3 = mock(StringValueResolver.class);
bf.addEmbeddedValueResolver(r1);
bf.addEmbeddedValueResolver(r2);
bf.addEmbeddedValueResolver(r3);
given(r1.resolveStringValue("A")).willReturn("B");
given(r2.resolveStringValue("B")).willReturn(null);
given(r3.resolveStringValue(isNull(String.class))).willThrow(new IllegalArgumentException());
bf.resolveEmbeddedValue("A");
verify(r1).resolveStringValue("A");
verify(r2).resolveStringValue("B");
verify(r3, never()).resolveStringValue(isNull(String.class));
}
示例7: processProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
*/
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
final ConfigurablePropertyResolver propertyResolver) throws BeansException {
propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
String resolved = (ignoreUnresolvablePlaceholders ?
propertyResolver.resolvePlaceholders(strVal) :
propertyResolver.resolveRequiredPlaceholders(strVal));
if (trimValues) {
resolved = resolved.trim();
}
return (resolved.equals(nullValue) ? null : resolved);
}
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
示例8: processProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
final ConfigurablePropertyResolver propertyResolver) throws BeansException {
propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
String resolved = ignoreUnresolvablePlaceholders ? propertyResolver.resolvePlaceholders(strVal)
: propertyResolver.resolveRequiredPlaceholders(strVal);
return (resolved.equals(nullValue) ? null : resolved);
}
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
开发者ID:xiangxik,项目名称:java-platform,代码行数:19,代码来源:ConfigurationPropertySourcesPlaceholderConfigurer.java
示例9: processProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
*/
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
final ConfigurablePropertyResolver propertyResolver) throws BeansException {
propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = new StringValueResolver() {
public String resolveStringValue(String strVal) {
String resolved = ignoreUnresolvablePlaceholders ?
propertyResolver.resolvePlaceholders(strVal) :
propertyResolver.resolveRequiredPlaceholders(strVal);
return (resolved.equals(nullValue) ? null : convertPropertyValue(resolved));
}
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:23,代码来源:EncryptablePropertySourcesPlaceholderConfigurer.java
示例10: processProperties
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
*/
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
final ConfigurablePropertyResolver propertyResolver) throws BeansException {
propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = new StringValueResolver() {
public String resolveStringValue(String strVal) {
String resolved = ignoreUnresolvablePlaceholders ?
propertyResolver.resolvePlaceholders(strVal) :
propertyResolver.resolveRequiredPlaceholders(strVal);
return (resolved.equals(nullValue) ? null : resolved);
}
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
示例11: setUp
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@Before
public void setUp() {
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
if ("${pattern}".equals(strVal)) {
return "#,##.00";
} else {
return strVal;
}
}
});
conversionService.addFormatterForFieldType(Number.class, new NumberFormatter());
conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
LocaleContextHolder.setLocale(Locale.US);
binder = new DataBinder(new TestBean());
binder.setConversionService(conversionService);
}
示例12: postProcessBeanFactory
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if(this.config==null){
this.config = this.beanFactory.getBean(ConfigSetting.class);
}
StringValueResolver valueResolver = new ConfigSettingStringValueResolver(config);
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
String[] beanNames = beanFactory.getBeanDefinitionNames();
for (String curName : beanNames) {
if (!(curName.equals(this.beanName) && beanFactory.equals(this.beanFactory))) {
BeanDefinition bd = beanFactory.getBeanDefinition(curName);
try {
visitor.visitBeanDefinition(bd);
}
catch (Exception ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage());
}
}
}
}
示例13: setEmbeddedValueResolver
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
for (SwaggerGeneratorContext context : contextList) {
if (EmbeddedValueResolverAware.class.isInstance(context)) {
((EmbeddedValueResolverAware) context).setEmbeddedValueResolver(resolver);
}
}
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:CompositeSwaggerGeneratorContext.java
示例14: testBasePathPlaceHolder
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@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());
}
示例15: testPathPlaceHolder
import org.springframework.util.StringValueResolver; //导入依赖的package包/类
@Test
public void testPathPlaceHolder() {
StringValueResolver stringValueResolver =
SpringUtils.createStringValueResolver(Collections.singletonMap("var", "varValue"));
PojoSwaggerGeneratorContext context = new PojoSwaggerGeneratorContext();
context.setEmbeddedValueResolver(stringValueResolver);
SwaggerGenerator swaggerGenerator = new SwaggerGenerator(context, null);
OperationGenerator operationGenerator = new OperationGenerator(swaggerGenerator, null);
operationGenerator.setPath("/a/${var}/b");
assertEquals("/a/varValue/b", operationGenerator.getPath());
}