1 16 17 package org.springframework.beans.factory.support; 18 19 import java.io.InputStream ; 20 import java.net.URL ; 21 22 import org.springframework.beans.factory.config.ConfigurableBeanFactory; 23 import org.springframework.beans.propertyeditors.InputStreamEditor; 24 import org.springframework.beans.propertyeditors.URLEditor; 25 import org.springframework.core.io.Resource; 26 import org.springframework.core.io.ResourceEditor; 27 import org.springframework.core.io.ResourceLoader; 28 import org.springframework.core.io.support.ResourceArrayPropertyEditor; 29 import org.springframework.core.io.support.ResourcePatternResolver; 30 31 40 public abstract class ConfigurableBeanFactoryUtils { 41 42 53 public static void registerResourceEditors( 54 ConfigurableBeanFactory beanFactory, ResourceLoader resourceLoader) { 55 56 ResourceEditor baseEditor = new ResourceEditor(resourceLoader); 57 beanFactory.registerCustomEditor(Resource.class, baseEditor); 58 beanFactory.registerCustomEditor(URL .class, new URLEditor(baseEditor)); 59 beanFactory.registerCustomEditor(InputStream .class, new InputStreamEditor(baseEditor)); 60 } 61 62 74 public static void registerResourceEditors( 75 ConfigurableBeanFactory beanFactory, ResourcePatternResolver resourcePatternResolver) { 76 77 registerResourceEditors(beanFactory, (ResourceLoader) resourcePatternResolver); 78 beanFactory.registerCustomEditor(Resource[].class, 79 new ResourceArrayPropertyEditor(resourcePatternResolver)); 80 } 81 82 } 83 | Popular Tags |