Java 类org.springframework.context.annotation.AnnotationConfigRegistry 实例源码
项目:graphql-java-datetime
文件:ContextHelper.java
static public AbstractApplicationContext load() {
AbstractApplicationContext context;
try {
context = AnnotationConfigApplicationContext.class.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
AnnotationConfigRegistry registry = (AnnotationConfigRegistry) context;
registry.register(BaseConfiguration.class);
registry.register(GraphQLJavaToolsAutoConfiguration.class);
context.refresh();
return context;
}
项目:spring-component-framework
文件:ApplicationFeatureResolver.java
private void scanAppRepository(AbstractApplicationContext context, Component component) {
String appRepository = component.getManifestAttribute(APP_REPOSITORY);
if (StringUtils.isEmpty(appRepository)) {
return;
}
int count;
if (context instanceof AnnotationConfigRegistry) {
int before = context.getBeanDefinitionCount();
((AnnotationConfigRegistry) context).scan(StringUtils.split(appRepository, CONFIG_LOCATION_DELIMITERS));
count = context.getBeanDefinitionCount() - before;
} else {
ClassPathBeanDefinitionScanner scanner =
new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) context);
scanner.setEnvironment(context.getEnvironment());
scanner.setResourceLoader(context);
scanner.setIncludeAnnotationConfig(false);
count = scanner.scan(StringUtils.split(appRepository, CONFIG_LOCATION_DELIMITERS));
}
if (count > 0 && logger.isDebugEnabled()) {
logger.debug("Scanned {} beans in {}", count, component.getDisplayName());
String[] names = context.getBeanDefinitionNames();
for (String name : names) {
BeanDefinition definition = ((GenericApplicationContext) context).getBeanDefinition(name);
if (definition instanceof ScannedGenericBeanDefinition) {
ScannedGenericBeanDefinition sgbd = (ScannedGenericBeanDefinition) definition;
Class<?> beanClass;
try {
beanClass = sgbd.resolveBeanClass(context.getClassLoader());
} catch (ClassNotFoundException e) {
continue;
}
if (beanClass != null) {
logger.debug("\t{}", beanClass.getName());
}
}
}
}
}