// first try to create annotation config application context
Class<?>[] annotatedClasses = new Class<?>[resources.length];
for (int i = 0; i < resources.length; i++) {
annotatedClasses[i] = this.classLoader.loadClass(resources[i]);
}
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(annotatedClasses);
context.setParent(parent);
context.setClassLoader(classLoader);
return context;
} catch (ClassNotFoundException e) {
// create generic application context
GenericApplicationContext context = new GenericApplicationContext(parent);
context.setClassLoader(classLoader);
ResourceLoader resourceLoader = new DefaultResourceLoader(classLoader);
context.setResourceLoader(resourceLoader);
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
for (String resource : resources) {
reader.loadBeanDefinitions(resourceLoader.getResource(resource));
}
context.refresh();
return context;
}
}