Beispiel #1
0
  @Override
  public InjectionContext<?, ?> create(Filter<Class<?>> filter) throws Exception {

    //
    DefaultListableBeanFactory factory;
    if (parent != null) {
      factory = new DefaultListableBeanFactory(parent);
    } else {
      if (configurationURL != null) {
        factory = new XmlBeanFactory(new UrlResource(configurationURL));
      } else {
        factory = new DefaultListableBeanFactory();
      }
    }

    //
    factory.setBeanClassLoader(classLoader);
    factory.setInstantiationStrategy(
        new SingletonInstantiationStrategy(new CglibSubclassingInstantiationStrategy(), instances));

    // Register scopes
    for (Scope scope : scopes) {
      if (!scope.isBuiltIn()) {
        factory.registerScope(
            scope.name().toLowerCase(), new SpringScope(factory, scope, scopeController));
      }
    }

    //
    for (Map.Entry<String, AbstractBean> entry : beans.entrySet()) {
      AbstractBean bean = entry.getValue();
      String name = entry.getKey();
      bean.configure(name, this, factory);
    }

    //
    AutowiredAnnotationBeanPostProcessor beanPostProcessor =
        new AutowiredAnnotationBeanPostProcessor();
    beanPostProcessor.setAutowiredAnnotationType(Inject.class);
    beanPostProcessor.setBeanFactory(factory);
    factory.addBeanPostProcessor(beanPostProcessor);

    //
    CommonAnnotationBeanPostProcessor commonAnnotationBeanProcessor =
        new CommonAnnotationBeanPostProcessor();
    factory.addBeanPostProcessor(commonAnnotationBeanProcessor);

    //
    Set cqt = new HashSet();
    cqt.add(Named.class);
    CustomAutowireConfigurer configurer = new CustomAutowireConfigurer();
    configurer.setCustomQualifierTypes(cqt);
    QualifierAnnotationAutowireCandidateResolver customResolver =
        new QualifierAnnotationAutowireCandidateResolver();
    factory.setAutowireCandidateResolver(customResolver);
    configurer.postProcessBeanFactory(factory);

    //
    return new SpringContext(scopeController, factory, classLoader);
  }
 @Bean
 @SuppressWarnings({"rawtypes", "serial", "unchecked"})
 public static CustomAutowireConfigurer customAutowireConfigurer() {
   CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
   cac.setCustomQualifierTypes(
       new HashSet() {
         {
           add(ComponentScanParserTests.CustomAnnotation.class);
         }
       });
   return cac;
 }