List of usage examples for org.springframework.core.convert.support DefaultConversionService getSharedInstance
public static ConversionService getSharedInstance()
From source file:jun.learn.scene.propertysource.AbstractPropertyResolver.java
/** * Convert the given value to the specified target type, if necessary. * @param value the original property value * @param targetType the specified target type for property retrieval * @return the converted value, or the original value if no conversion * is necessary// www . j a v a 2 s . co m * @since 4.3.5 */ @SuppressWarnings("unchecked") protected <T> T convertValueIfNecessary(Object value, Class<T> targetType) { if (targetType == null) { return (T) value; } ConversionService conversionServiceToUse = this.conversionService; if (conversionServiceToUse == null) { // Avoid initialization of shared DefaultConversionService if // no standard type conversion is needed in the first place... if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } conversionServiceToUse = DefaultConversionService.getSharedInstance(); } return conversionServiceToUse.convert(value, targetType); }
From source file:org.springframework.core.env.AbstractPropertyResolver.java
/** * Convert the given value to the specified target type, if necessary. * @param value the original property value * @param targetType the specified target type for property retrieval * @return the converted value, or the original value if no conversion * is necessary/*w ww .j a v a 2s . c o m*/ * @since 4.3.5 */ @SuppressWarnings("unchecked") @Nullable protected <T> T convertValueIfNecessary(Object value, @Nullable Class<T> targetType) { if (targetType == null) { return (T) value; } ConversionService conversionServiceToUse = this.conversionService; if (conversionServiceToUse == null) { // Avoid initialization of shared DefaultConversionService if // no standard type conversion is needed in the first place... if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } conversionServiceToUse = DefaultConversionService.getSharedInstance(); } return conversionServiceToUse.convert(value, targetType); }
From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java
@SuppressWarnings("unchecked") public AbstractMethodAnnotationPostProcessor(ConfigurableListableBeanFactory beanFactory) { Assert.notNull(beanFactory, "'beanFactory' must not be null"); this.messageHandlerAttributes.add(SEND_TIMEOUT_ATTRIBUTE); this.beanFactory = beanFactory; ConversionService conversionService = this.beanFactory.getConversionService(); if (conversionService != null) { this.conversionService = conversionService; } else {//from w w w . ja va2 s . c o m this.conversionService = DefaultConversionService.getSharedInstance(); } this.channelResolver = new BeanFactoryChannelResolver(beanFactory); this.annotationType = (Class<T>) GenericTypeResolver.resolveTypeArgument(this.getClass(), MethodAnnotationPostProcessor.class); }