Search in sources :

Example 1 with AnnotationBeanNameGenerator

use of cn.taketoday.context.annotation.AnnotationBeanNameGenerator in project today-infrastructure by TAKETODAY.

the class ConfigurationBeanNameTests method registerOuterConfig_withBeanNameGenerator.

@Test
public void registerOuterConfig_withBeanNameGenerator() {
    StandardApplicationContext ctx = new StandardApplicationContext();
    ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {

        @Override
        public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
            return "custom-" + super.generateBeanName(definition, registry);
        }
    });
    ctx.register(A.class);
    ctx.refresh();
    assertThat(ctx.containsBean("custom-outer")).isTrue();
    assertThat(ctx.containsBean("custom-imported")).isTrue();
    assertThat(ctx.containsBean("custom-nested")).isTrue();
    assertThat(ctx.containsBean("nestedBean")).isTrue();
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) AnnotationBeanNameGenerator(cn.taketoday.context.annotation.AnnotationBeanNameGenerator) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotationBeanNameGenerator

use of cn.taketoday.context.annotation.AnnotationBeanNameGenerator in project today-framework by TAKETODAY.

the class ConfigurationBeanNameTests method registerOuterConfig_withBeanNameGenerator.

@Test
public void registerOuterConfig_withBeanNameGenerator() {
    StandardApplicationContext ctx = new StandardApplicationContext();
    ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {

        @Override
        public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
            return "custom-" + super.generateBeanName(definition, registry);
        }
    });
    ctx.register(A.class);
    ctx.refresh();
    assertThat(ctx.containsBean("custom-outer")).isTrue();
    assertThat(ctx.containsBean("custom-imported")).isTrue();
    assertThat(ctx.containsBean("custom-nested")).isTrue();
    assertThat(ctx.containsBean("nestedBean")).isTrue();
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) AnnotationBeanNameGenerator(cn.taketoday.context.annotation.AnnotationBeanNameGenerator) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)2 AnnotationBeanNameGenerator (cn.taketoday.context.annotation.AnnotationBeanNameGenerator)2 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)2 Test (org.junit.jupiter.api.Test)2