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

ConfigurationClassBeanDefinitionReader.java 文件源码 项目:lams 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
ConfigurationClassBeanDefinitionReader.java 文件源码 项目:spring4-understanding 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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 + "'");
    }
}
ConfigurationClassBeanDefinitionReader.java 文件源码 项目:my-spring-cache-redis 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java 文件源码 项目:joinfaces 阅读 19 收藏 0 点赞 0 评论 0
@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);
}
JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java 文件源码 项目:joinfaces 阅读 18 收藏 0 点赞 0 评论 0
@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);
}
JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java 文件源码 项目:joinfaces 阅读 15 收藏 0 点赞 0 评论 0
@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("");

}
ConfigurationClassBeanDefinitionReader.java 文件源码 项目:spring 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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 + "'");
    }
}
ConfigurationClassBeanDefinitionReader.java 文件源码 项目:class-guard 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
AnnotatedBeanDefinitionReader.java 文件源码 项目:lams 阅读 20 收藏 0 点赞 0 评论 0
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);
}
MyBeanFactoryPostProcessor.java 文件源码 项目:springboot-analysis 阅读 20 收藏 0 点赞 0 评论 0
@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
        );
    }
}
AnnotatedBeanDefinitionReader.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
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);
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 17 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 17 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
@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());
}
AnnotationScopeMetadataResolverTests.java 文件源码 项目:spring4-understanding 阅读 17 收藏 0 点赞 0 评论 0
@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());
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 37 收藏 0 点赞 0 评论 0
@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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 25 收藏 0 点赞 0 评论 0
@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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 32 收藏 0 点赞 0 评论 0
@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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertEquals("henry", beanName);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 22 收藏 0 点赞 0 评论 0
/**
 * @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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
/**
 * @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);
}
AnnotationBeanNameGeneratorTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
/**
 * @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);
}
AnnotatedBeanDefinitionReader.java 文件源码 项目:my-spring-cache-redis 阅读 18 收藏 0 点赞 0 评论 0
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);
}
AbstractDevToolsDataSourceAutoConfigurationTests.java 文件源码 项目:https-github.com-g0t4-jenkins2-course-spring-boot 阅读 16 收藏 0 点赞 0 评论 0
@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();
}
MyBeanDefinitionRegistryPostProcessor.java 文件源码 项目:kekoa 阅读 20 收藏 0 点赞 0 评论 0
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);
}


问题


面经


文章

微信
公众号

扫码关注公众号