/** * Create a new SimpleMetadataReaderFactory for the default class loader. */ public SimpleMetadataReaderFactory() { this.resourceLoader = new DefaultResourceLoader(); }
/** * Create a new embedded database builder with a {@link DefaultResourceLoader}. */ public EmbeddedDatabaseBuilder() { this(new DefaultResourceLoader()); }
/** * Create a new instance of the {@link ResourceEditor} class * using a {@link DefaultResourceLoader} and {@link StandardEnvironment}. */ public ResourceEditor() { this(new DefaultResourceLoader(), null); }
private ResourceLoader deduceResourceLoader(@Nullable BeanDefinitionRegistry source) { if (source instanceof ResourceLoader) { return (ResourceLoader) source; } return new DefaultResourceLoader(); }
/** * Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader. * @param classLoader the ClassLoader to load classpath resources with, * or {@code null} for using the thread context class loader * at the time of actual resource access * @see org.springframework.core.io.DefaultResourceLoader */ public PathMatchingResourcePatternResolver(@Nullable ClassLoader classLoader) { this.resourceLoader = new DefaultResourceLoader(classLoader); }
/** * Create a PropertySource based on Properties loaded from the given resource * location and use the given class loader to load the resource, assuming it is * prefixed with {@code classpath:}. The name of the PropertySource will be * generated based on the {@link Resource#getDescription() description} of the * resource. */ public ResourcePropertySource(String location, ClassLoader classLoader) throws IOException { this(new DefaultResourceLoader(classLoader).getResource(location)); }
@Override public void initialize() { if (this.resourceLoader == null) { this.resourceLoader = SchedulerFactoryBean.getConfigTimeResourceLoader(); if (this.resourceLoader == null) { this.resourceLoader = new DefaultResourceLoader(); } } }
/** * Create a PropertySource having the given name based on Properties loaded from * the given resource location. The default thread context class loader will be * used to load the resource (assuming the location string is prefixed with * {@code classpath:}. */ public ResourcePropertySource(String name, String location) throws IOException { this(name, new DefaultResourceLoader().getResource(location)); }
@Test public void defaultDomainWithIndex() { this.manager.setPackagesToScan("org.springframework.orm.jpa.domain"); this.manager.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.index(getClass().getClassLoader(), new ClassPathResource("spring.components", Person.class)))); testDefaultDomain(); }
@Test public void defaultsWithScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); provider.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); testDefault(provider, ScannedGenericBeanDefinition.class); }
@Test public void antStylePackageWithScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); provider.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); testAntStyle(provider, ScannedGenericBeanDefinition.class); }
@Test public void customSupportedIncludeAndExcludedFilterWithScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); testCustomSupportedIncludeAndExcludeFilter(provider, ScannedGenericBeanDefinition.class); }
@Test public void defaultDomainWithScan() { this.manager.setPackagesToScan("org.springframework.orm.jpa.domain"); this.manager.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); testDefaultDomain(); }
@Test public void customAnnotationTypeIncludeFilterWithScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); testCustomAnnotationTypeIncludeFilter(provider, ScannedGenericBeanDefinition.class); }
@Test public void excludeFilterWithScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); provider.setResourceLoader(new DefaultResourceLoader( CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()))); provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*Named.*"))); testExclude(provider, ScannedGenericBeanDefinition.class); }
@Test public void bogusPackageWithIndex() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER)); Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus"); assertEquals(0, candidates.size()); }
@Test public void excludeFilterWithIndex() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER)); provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*Named.*"))); testExclude(provider, AnnotatedGenericBeanDefinition.class); }
@Test // SPR-12448 public void freeMarkerConfigurationAsBean() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class); loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader()); loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker"); RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class); configDef.getPropertyValues().add("templateLoader", loaderDef); beanFactory.registerBeanDefinition("freeMarkerConfig", configDef); beanFactory.getBean(Configuration.class); }
@Override protected ConfigurationClassParser newParser() { return new ConfigurationClassParser( new CachingMetadataReaderFactory(), new FailFastProblemReporter(), new StandardEnvironment(), new DefaultResourceLoader(), new AnnotationBeanNameGenerator(), new DefaultListableBeanFactory()); }
@Test public void customSupportIncludeFilterWithNonIndexedTypeUseScan() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER)); // This annotation type is not directly annotated with Indexed so we can use // the index to find candidates provider.addIncludeFilter(new AnnotationTypeFilter(CustomStereotype.class)); Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE); assertTrue(containsBeanClass(candidates, DefaultNamedComponent.class)); assertEquals(1, candidates.size()); assertBeanDefinitionType(candidates, ScannedGenericBeanDefinition.class); }