use of org.springframework.core.type.classreading.CachingMetadataReaderFactory in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessor method setResourceLoader.
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
Assert.notNull(resourceLoader, "ResourceLoader must not be null");
this.resourceLoader = resourceLoader;
if (!this.setMetadataReaderFactoryCalled) {
this.metadataReaderFactory = new CachingMetadataReaderFactory(resourceLoader);
}
}
use of org.springframework.core.type.classreading.CachingMetadataReaderFactory in project spring-framework by spring-projects.
the class DefaultPersistenceUnitManager method scanPackage.
private void scanPackage(SpringPersistenceUnitInfo scannedUnit, String pkg) {
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(pkg) + CLASS_RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
URL url = resource.getURL();
if (ResourceUtils.isJarURL(url)) {
scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
}
}
} else if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
scannedUnit.addManagedPackage(className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
}
}
}
} catch (IOException ex) {
throw new PersistenceException("Failed to scan classpath for unlisted entity classes", ex);
}
}
use of org.springframework.core.type.classreading.CachingMetadataReaderFactory in project spring-boot by spring-projects.
the class CloudAutoConfigurationTests method testOrder.
@Test
public void testOrder() throws Exception {
TestAutoConfigurationSorter sorter = new TestAutoConfigurationSorter(new CachingMetadataReaderFactory());
Collection<String> classNames = new ArrayList<>();
classNames.add(MongoAutoConfiguration.class.getName());
classNames.add(DataSourceAutoConfiguration.class.getName());
classNames.add(MongoRepositoriesAutoConfiguration.class.getName());
classNames.add(JpaRepositoriesAutoConfiguration.class.getName());
classNames.add(CloudAutoConfiguration.class.getName());
List<String> ordered = sorter.getInPriorityOrder(classNames);
assertThat(ordered.get(0)).isEqualTo(CloudAutoConfiguration.class.getName());
}
use of org.springframework.core.type.classreading.CachingMetadataReaderFactory in project spring-boot by spring-projects.
the class NoSuchBeanDefinitionFailureAnalyzer method setBeanFactory.
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory);
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
this.metadataReaderFactory = new CachingMetadataReaderFactory(this.beanFactory.getBeanClassLoader());
// Get early as won't be accessible once context has failed to start
this.report = ConditionEvaluationReport.get(this.beanFactory);
}
use of org.springframework.core.type.classreading.CachingMetadataReaderFactory in project spring-framework by spring-projects.
the class ClassPathJaxb2TypeScanner method scanPackages.
/**
* Scan the packages for classes marked with JAXB2 annotations.
* @throws UncategorizedMappingException in case of errors
*/
public Class<?>[] scanPackages() throws UncategorizedMappingException {
try {
List<Class<?>> jaxb2Classes = new ArrayList<>();
for (String packageToScan : this.packagesToScan) {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageToScan) + RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
if (isJaxb2Class(metadataReader, metadataReaderFactory)) {
String className = metadataReader.getClassMetadata().getClassName();
Class<?> jaxb2AnnotatedClass = this.resourcePatternResolver.getClassLoader().loadClass(className);
jaxb2Classes.add(jaxb2AnnotatedClass);
}
}
}
return jaxb2Classes.toArray(new Class<?>[jaxb2Classes.size()]);
} catch (IOException ex) {
throw new UncategorizedMappingException("Failed to scan classpath for unlisted classes", ex);
} catch (ClassNotFoundException ex) {
throw new UncategorizedMappingException("Failed to load annotated classes from classpath", ex);
}
}
Aggregations