SpringUtils { public static Resource newPathResource(String location){ Assert.hasText(location); Resource resource = null; if(location.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)){ String classpath = StringUtils.substringAfter(location, ResourceUtils.CLASSPATH_URL_PREFIX); resource = new ClassPathResource(classpath); }else{ resource = new FileSystemResource(location); } return resource; } private  SpringUtils(); static int higherThan(int order); static int higherThan(int order, int step); static int lowerThan(int order); static int lowerThan(int order, int step); static FormattingConversionService getFormattingConversionService(); static T convertValue(Object value, Class<T> targetType); static Object convertValue(Object value, Class<?> clazz, String name, boolean byProperty); static Map<String, Object> toFlatMap(Object obj); static TypeDescriptor typeDescriptorForPerperty(Class<?> clazz, String propertyName); static TypeDescriptor typeDescriptorForField(Class<?> clazz, String fieldName); static void setProfiles(String profiles); static String getProfiles(); static void addProfiles(String... profiles); static List<WithAnnotationBeanData<T>> getBeansWithAnnotation(ApplicationContext applicationContext, Class<T> annotationType); static T getBeanWithAnnotation(ApplicationContext applicationContext, Class<? extends Annotation> annotationType); static List<T> getBeans(ListableBeanFactory appContext, Class<T> clazz); static List<T> getBeans(ListableBeanFactory appContext, Class<?> clazz, ParameterizedTypeReference<T> typeRef); static Map<String, T> getBeansAsMap(ApplicationContext appContext, Class<T> clazz); static T getBean(ListableBeanFactory appContext, Class<T> clazz); static T getBean(ApplicationContext appContext, String beanName); static T getHighestOrder(ApplicationContext appContext, Class<T> clazz); static T getLowestOrder(ApplicationContext appContext, Class<T> clazz); static PropertyPlaceholderConfigurer newApplicationConf(String... locations); static PropertyPlaceholderConfigurer newApplicationConf(boolean searchSystemEnvironment, String... locations); static boolean isSpringConfPlaceholder(String value); static Resource newPathResource(String location); static Resource newClassPathResource(String location); static Properties createProperties(String location, boolean throwIfError); static JFishProperties loadAsJFishProperties(String... classpaths); static PropertiesFactoryBean createPropertiesBySptring(String...classpaths); static PropertiesFactoryBean createPropertiesBySptring(JFishProperties properties, String...classpaths); static AutowireCapableBeanFactory findAutoWiringBeanFactory(ApplicationContext context); static BeanDefinition createBeanDefinition(Class<?> beanClass, Object[] constructorArgs, Map<String, Object> properties); static void autowireBean(ApplicationContext appContext, T existingBean); static void injectAndInitialize(ApplicationContext appContext, T bean); static void injectAndInitialize(AutowireCapableBeanFactory acb, T bean, int autowireMode); static void initializeBean(AutowireCapableBeanFactory acb, T bean); static void initializeBean(ApplicationContext appContext, T bean); static T registerBean(BeanFactory context, Class<?> beanClass, Object...params); static T registerBean(BeanFactory context, String beanName, Class<?> beanClass, Object...params); static BeanDefinition registerBeanDefinition(Object context, String beanName, Class<?> beanClass, Object...params); static SingletonBeanRegistry getSingletonBeanRegistry(Object applicationContext); static BeanDefinitionRegistry getBeanDefinitionRegistry(Object applicationContext); static BeanDefinitionRegistry getBeanDefinitionRegistry(Object applicationContext, boolean throwIfNull); static void registerSingleton(BeanFactory applicationContext, String beanName, Object singletonObject); static void registerAndInitSingleton(ApplicationContext applicationContext, String beanName, Object singletonObject); static Resource classpath(String path); static InputStream classpathStream(String path); static BeanWrapper newBeanWrapper(Object obj); static ConfigurablePropertyAccessor newPropertyAccessor(Object obj, boolean directFieldAccess); static BeanWrapper newBeanMapWrapper(Object obj, Object...listElementTypes); static T map2Bean(Map<String, ?> props, Class<T> beanClass); static T setMap2Bean(Map<String, ?> props, T bean); static Map<String, Object> beansOfAnnotationIncludingAncestors(ListableBeanFactory lbf, Class<? extends Annotation> annotationType); static String[] getConstructorNames(Class<?> clazz); static String[] getConstructorNames(Class<?> clazz, int constructorIndex); static String[] getConstructorNames(Constructor<?> targetConstructor); static Class<?> getTargetClass(Object candidate); static boolean scanAnnotation(ApplicationContext applicationContext, Class<? extends Annotation> annoClass, BiConsumer<Object, Class<?>> consumer); static boolean scanAnnotation(ListableBeanFactory beanFactory, Class<? extends Annotation> annoClass, BiConsumer<Object, Class<?>> consumer); static AnnotationAttributes getAnnotationAttributes(AnnotatedTypeMetadata metadata, Class<?> annoType); static Optional<AnnotationAttributes> getAnnotationAttributes(Method method, Class<? extends Annotation> annoClass, boolean searchOnClass); static Optional<AnnotationAttributes> getAnnotationAttributes(Method method, Class<? extends Annotation> annoClass); static String resolvePlaceholders(Object applicationContext, String value); static String resolvePlaceholders(Object applicationContext, String value, boolean throwIfNotResolved); static T toBean(Map<String, ?> propValues, Class<T> beanClass); static MapToBeanConvertor getMapToBean(); static String readClassPathFile(String path); static String readClassPathFile(String path, String charset); static String readMultipartFile(MultipartFile multipartFile); static String readMultipartFile(MultipartFile multipartFile, String charset); static InputStream getInputStream(Resource resource); static BeanToMapConvertor getBeanToMapConvertor(String... excludeProperties); static Set<Method> selectMethodsByParameterTypes(Class<?> targetClass, String targetMethod, Method sourceMethod); static final Expression DOLOR; }
@Test public void testNewPathResource() throws Exception{ Resource res = SpringUtils.newPathResource("classpath:/org"); assertThat(res).isInstanceOf(ClassPathResource.class); System.out.println("path:"+res.getFile()); res = SpringUtils.newPathResource("D:/tmp"); assertThat(res).isInstanceOf(FileSystemResource.class); System.out.println("path:"+res.getFile()); }