Java 类org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition 实例源码

项目:lams    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    BeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);
    if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
        String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
        this.registry.registerBeanDefinition(configBeanName, configBeanDef);
        configClass.setBeanName(configBeanName);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
        }
    }
    else {
        this.problemReporter.error(
                new InvalidConfigurationImportProblem(metadata.getClassName(), configClass.getResource(), metadata));
    }
}
项目:spring4-understanding    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

    ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
    configBeanDef.setScope(scopeMetadata.getScopeName());
    String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
    AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
    configClass.setBeanName(configBeanName);

    if (logger.isDebugEnabled()) {
        logger.debug("Registered bean definition for imported class '" + configBeanName + "'");
    }
}
项目:my-spring-cache-redis    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    BeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);
    if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
        String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
        this.registry.registerBeanDefinition(configBeanName, configBeanDef);
        configClass.setBeanName(configBeanName);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
        }
    }
    else {
        this.problemReporter.error(
                new InvalidConfigurationImportProblem(metadata.getClassName(), configClass.getResource(), metadata));
    }
}
项目:joinfaces    文件:JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java   
@Test
public void testViewScopedClass() {
    GenericApplicationContext acx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

    acx.registerBeanDefinition("viewScopedClass", new AnnotatedGenericBeanDefinition(
        new StandardAnnotationMetadata(ViewScopedClass.class)));
    acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
        ScopedBeansConfiguration.class));
    acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.refresh();

    assertThat(acx.getBeanDefinition("viewScopedClass").getScope())
        .isEqualTo(ViewScope.SCOPE_VIEW);
    assertThat(acx.getBeanDefinition("viewScopedBean").getScope())
        .isEqualTo(ViewScope.SCOPE_VIEW);
}
项目:joinfaces    文件:JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java   
@Test
public void testSessionScopedClass() {
    GenericApplicationContext acx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

    acx.registerBeanDefinition("sessionScopedClass", new AnnotatedGenericBeanDefinition(
        new StandardAnnotationMetadata(SessionScopedClass.class)));
    acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
        ScopedBeansConfiguration.class));
    acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.refresh();

    assertThat(acx.getBeanDefinition("sessionScopedClass").getScope())
        .isEqualTo(WebApplicationContext.SCOPE_SESSION);
    assertThat(acx.getBeanDefinition("sessionScopedBean").getScope())
        .isEqualTo(WebApplicationContext.SCOPE_SESSION);
}
项目:joinfaces    文件:JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java   
@Test
public void testNoScopedClass() {
    GenericApplicationContext acx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

    acx.registerBeanDefinition("noScopedClass", new AnnotatedGenericBeanDefinition(
        new StandardAnnotationMetadata(NoScopedClass.class)));
    acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
        ScopedBeansConfiguration.class));
    acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
    acx.refresh();

    assertThat(acx.getBeanDefinition("noScopedClass").getScope())
        .isEqualTo("");
    assertThat(acx.getBeanDefinition("noScopedBean").getScope())
        .isEqualTo("");

}
项目:spring    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    AnnotatedGenericBeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);

    ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
    configBeanDef.setScope(scopeMetadata.getScopeName());
    String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
    AnnotationConfigUtils.processCommonDefinitionAnnotations(configBeanDef, metadata);

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
    configClass.setBeanName(configBeanName);

    if (logger.isDebugEnabled()) {
        logger.debug("Registered bean definition for imported class '" + configBeanName + "'");
    }
}
项目:class-guard    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    BeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);
    if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
        String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
        this.registry.registerBeanDefinition(configBeanName, configBeanDef);
        configClass.setBeanName(configBeanName);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
        }
    }
    else {
        this.problemReporter.error(
                new InvalidConfigurationImportProblem(metadata.getClassName(), configClass.getResource(), metadata));
    }
}
项目:lams    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:springboot-analysis    文件:MyBeanFactoryPostProcessor.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    System.out.println("------ register custom bean in BeanFactoryPostProcessor");
    beanFactory.registerSingleton("createByBeanFactoryPostProcessor", new SimpleBeanInBeanFactoryPostProcessor());
    if(beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionReaderUtils.registerBeanDefinition(
                new BeanDefinitionHolder(new AnnotatedGenericBeanDefinition(SimpleBeanWithDefinitionInBeanFactoryPostProcessor.class), "simpleBeanWithDefinitionInBeanFactoryPostProcessor"),                             (BeanDefinitionRegistry) beanFactory
        );
    }
}
项目:spring4-understanding    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class == qualifier) {
                abd.setPrimary(true);
            }
            else if (Lazy.class == qualifier) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName());
    assertEquals(NO, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void resolveScopeMetadataShouldApplyScopedProxyModeToPrototype() {
    this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES);
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
    assertEquals(INTERFACES, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void resolveScopeMetadataShouldReadScopedProxyModeFromAnnotation() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScope() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(NO, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScopeViaAsm() throws IOException {
    MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
    MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName());
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(NO, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScopeWithAttribute() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
        AnnotatedWithCustomRequestScopeWithAttributeOverride.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScopeWithAttributeViaAsm() throws IOException {
    MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
    MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName());
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameWithNamedComponent() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertNotNull("The generated beanName must *never* be null.", beanName);
    assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
    assertEquals("walden", beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameWithDefaultNamedComponent() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(DefaultNamedComponent.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertNotNull("The generated beanName must *never* be null.", beanName);
    assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
    assertEquals("thoreau", beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameWithNamedComponentWhereTheNameIsBlank() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithBlankName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertNotNull("The generated beanName must *never* be null.", beanName);
    assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertEquals(expectedGeneratedBeanName, beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertNotNull("The generated beanName must *never* be null.", beanName);
    assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertEquals(expectedGeneratedBeanName, beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertEquals("henry", beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
@Test
public void generateBeanNameFromMetaComponentWithNonStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithoutName() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertEquals(expectedGeneratedBeanName, beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertEquals(expectedGeneratedBeanName, beanName);
}
项目:spring4-understanding    文件:AnnotationBeanNameGeneratorTests.java   
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
        ComposedControllerAnnotationWithStringValue.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertEquals("restController", beanName);
}
项目:my-spring-cache-redis    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AbstractDevToolsDataSourceAutoConfigurationTests.java   
@Test
public void emptyFactoryMethodMetadataIgnored() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    DataSource dataSource = mock(DataSource.class);
    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
            dataSource.getClass());
    context.registerBeanDefinition("dataSource", beanDefinition);
    context.register(DataSourcePropertiesConfiguration.class);
    context.register(DevToolsDataSourceAutoConfiguration.class);
    context.refresh();
    context.close();
}
项目:kekoa    文件:MyBeanDefinitionRegistryPostProcessor.java   
private void registerBean(BeanDefinitionRegistry registry, String name,Class<?> beanClass) {
    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    // 可以自动生成name
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, registry));

    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd,beanName);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder,registry);
}
项目:spring    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class == qualifier) {
                abd.setPrimary(true);
            }
            else if (Lazy.class == qualifier) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:spring-boot-concourse    文件:AbstractDevToolsDataSourceAutoConfigurationTests.java   
@Test
public void emptyFactoryMethodMetadataIgnored() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

    DataSource dataSource = mock(DataSource.class);
    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
            dataSource.getClass());
    context.registerBeanDefinition("dataSource", beanDefinition);
    context.register(DataSourcePropertiesConfiguration.class);
    context.register(DevToolsDataSourceAutoConfiguration.class);
    context.refresh();
    context.close();
}
项目:Mycat-openEP    文件:SpringInitializer.java   
private static void initAnnotatedConf(GenericApplicationContext context){
    Class componentScanAnnotated=ProcessInfo.getAnnotationInitClass();
    if(componentScanAnnotated!=null){
        AnnotatedGenericBeanDefinition def=new AnnotatedGenericBeanDefinition(ProcessInfo.getAnnotationInitClass());
        AnnotatedBeanDefinitionReader reader=new AnnotatedBeanDefinitionReader(context);
        AnnotationScopeMetadataResolver resolver=new AnnotationScopeMetadataResolver();
        resolver.resolveScopeMetadata(def);
        reader.setScopeMetadataResolver(resolver);
    }
}
项目:mybatis-spring-1.2.2    文件:ClassPathScanningCandidateComponentProvider.java   
private Set<BeanDefinition> findKopBeanComponents(String basePackage){
    boolean debugEnabled = logger.isDebugEnabled();
    Set<BeanDefinition> candidates = new LinkedHashSet<BeanDefinition>();
    List<String> classes = null;
    if(basePackage.contains("com.linda.koala.biz.dao")){
        classes = this.getDaoClasses();
    }else if(basePackage.contains("com.linda.koala.biz")){
        classes = this.getBizClasses();
    }
    if(classes!=null){
        for(String clazz:classes){
            ClassLoader loader = this.getClass().getClassLoader();
            try {
                Class<?> class1 = loader.loadClass(clazz);
                if(class1!=null){

                    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(class1);
                    if (isCandidateComponent(beanDefinition)) {
                        if (debugEnabled) {
                            logger.debug("Identified candidate component class: " + clazz);
                        }
                        candidates.add(beanDefinition);
                    }
                    else {
                        if (debugEnabled) {
                            logger.debug("Ignored because not a concrete top-level class: " +clazz);
                        }
                    }
                }
            } catch (ClassNotFoundException e) {
                throw new BeanDefinitionStoreException("Failed to read candidate component class: " + clazz, e);
            }
        }
    }
    return candidates;
}
项目:xsf    文件:RouteRegistrar.java   
/**
 * loadClass: Loads the route class into the bean defn registry.
 * @param bdr
 * @param className
 */
private void loadClass(BeanDefinitionRegistry bdr, String className) {

    try {
        // try using the class loader to load the given route class
        Class<?> clazz = Class.forName(className);

        // define it in the registry under it's own class name.
        bdr.registerBeanDefinition(className, new AnnotatedGenericBeanDefinition(clazz));
    } catch (ClassNotFoundException e) {
        _logger.error("XSF Route Registrator could not locate class="+className, e);
    }
}
项目:class-guard    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) {
    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    AnnotationMetadata metadata = abd.getMetadata();
    if (metadata.isAnnotated(Profile.class.getName())) {
        AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
        if (!this.environment.acceptsProfiles(profile.getStringArray("value"))) {
            return;
        }
    }
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }
    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:class-guard    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
}
项目:class-guard    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
    this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
}
项目:class-guard    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void testThatResolveScopeMetadataDoesReadScopedProxyModeFromTheAnnotation() {
    this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
项目:class-guard    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void testCustomRequestScope() {
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
}