Search in sources :

Example 1 with BeanNameGenerator

use of cn.taketoday.beans.factory.support.BeanNameGenerator in project today-infrastructure by TAKETODAY.

the class ApplicationTests method customBeanNameGeneratorWithNonWebApplication.

@Test
void customBeanNameGeneratorWithNonWebApplication() {
    TestApplication application = new TestApplication(ExampleWebConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
    application.setBeanNameGenerator(beanNameGenerator);
    this.context = application.run();
    then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator);
    Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
    assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
Also used : BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with BeanNameGenerator

use of cn.taketoday.beans.factory.support.BeanNameGenerator in project today-infrastructure by TAKETODAY.

the class ApplicationTests method customBeanNameGenerator.

@Test
void customBeanNameGenerator() {
    TestApplication application = new TestApplication(ExampleWebConfig.class);
    BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
    application.setBeanNameGenerator(beanNameGenerator);
    this.context = application.run();
    then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator);
    Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
    assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
Also used : BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) Test(org.junit.jupiter.api.Test)

Example 3 with BeanNameGenerator

use of cn.taketoday.beans.factory.support.BeanNameGenerator in project today-infrastructure by TAKETODAY.

the class MapperScannerBeanDefinitionParser method parseInternal.

/**
 * {@inheritDoc}
 */
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
    builder.addPropertyValue("processPropertyPlaceHolders", true);
    try {
        String annotationClassName = element.getAttribute(ATTRIBUTE_ANNOTATION);
        if (StringUtils.hasText(annotationClassName)) {
            Class<? extends Annotation> annotationClass = ClassUtils.forName(annotationClassName);
            builder.addPropertyValue("annotationClass", annotationClass);
        }
        String markerInterfaceClassName = element.getAttribute(ATTRIBUTE_MARKER_INTERFACE);
        if (StringUtils.hasText(markerInterfaceClassName)) {
            Class<?> markerInterface = ClassUtils.forName(markerInterfaceClassName);
            builder.addPropertyValue("markerInterface", markerInterface);
        }
        String nameGeneratorClassName = element.getAttribute(ATTRIBUTE_NAME_GENERATOR);
        if (StringUtils.hasText(nameGeneratorClassName)) {
            Class<BeanNameGenerator> nameGeneratorClass = ClassUtils.forName(nameGeneratorClassName);
            BeanNameGenerator nameGenerator = BeanUtils.newInstance(nameGeneratorClass);
            builder.addPropertyValue("nameGenerator", nameGenerator);
        }
        String mapperFactoryBeanClassName = element.getAttribute(ATTRIBUTE_MAPPER_FACTORY_BEAN_CLASS);
        if (StringUtils.hasText(mapperFactoryBeanClassName)) {
            Class<? extends MapperFactoryBean> mapperFactoryBeanClass = ClassUtils.forName(mapperFactoryBeanClassName);
            builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
        }
    } catch (Exception ex) {
        XmlReaderContext readerContext = parserContext.getReaderContext();
        readerContext.error(ex.getMessage(), readerContext.extractSource(element), ex.getCause());
    }
    builder.addPropertyValue("basePackage", element.getAttribute(ATTRIBUTE_BASE_PACKAGE));
    builder.addPropertyValue("defaultScope", element.getAttribute(ATTRIBUTE_DEFAULT_SCOPE));
    builder.addPropertyValue("sqlSessionFactoryBeanName", element.getAttribute(ATTRIBUTE_FACTORY_REF));
    builder.addPropertyValue("lazyInitialization", element.getAttribute(ATTRIBUTE_LAZY_INITIALIZATION));
    builder.addPropertyValue("sqlSessionTemplateBeanName", element.getAttribute(ATTRIBUTE_TEMPLATE_REF));
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    return builder.getBeanDefinition();
}
Also used : BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) BeanDefinitionBuilder(cn.taketoday.beans.factory.support.BeanDefinitionBuilder) XmlReaderContext(cn.taketoday.beans.factory.xml.XmlReaderContext)

Example 4 with BeanNameGenerator

use of cn.taketoday.beans.factory.support.BeanNameGenerator in project today-framework by TAKETODAY.

the class ApplicationTests method customBeanNameGenerator.

@Test
void customBeanNameGenerator() {
    TestApplication application = new TestApplication(ExampleWebConfig.class);
    BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
    application.setBeanNameGenerator(beanNameGenerator);
    this.context = application.run();
    then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator);
    Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
    assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
Also used : BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) Test(org.junit.jupiter.api.Test)

Example 5 with BeanNameGenerator

use of cn.taketoday.beans.factory.support.BeanNameGenerator in project today-framework by TAKETODAY.

the class ApplicationTests method customBeanNameGeneratorWithNonWebApplication.

@Test
void customBeanNameGeneratorWithNonWebApplication() {
    TestApplication application = new TestApplication(ExampleWebConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
    application.setBeanNameGenerator(beanNameGenerator);
    this.context = application.run();
    then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator);
    Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
    assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
Also used : BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

BeanNameGenerator (cn.taketoday.beans.factory.support.BeanNameGenerator)10 BeanDefinitionBuilder (cn.taketoday.beans.factory.support.BeanDefinitionBuilder)4 DefaultBeanNameGenerator (cn.taketoday.beans.factory.support.DefaultBeanNameGenerator)4 Test (org.junit.jupiter.api.Test)4 XmlReaderContext (cn.taketoday.beans.factory.xml.XmlReaderContext)2 AnnotatedBeanDefinitionReader (cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader)2 AnnotationBeanNameGenerator (cn.taketoday.context.annotation.AnnotationBeanNameGenerator)2 ClassPathBeanDefinitionScanner (cn.taketoday.context.annotation.ClassPathBeanDefinitionScanner)2 ScopeMetadataResolver (cn.taketoday.context.loader.ScopeMetadataResolver)2 MergedAnnotation (cn.taketoday.core.annotation.MergedAnnotation)2 MapperFactoryBean (cn.taketoday.orm.mybatis.mapper.MapperFactoryBean)2 ClassUtils (cn.taketoday.util.ClassUtils)2 StringUtils (cn.taketoday.util.StringUtils)2 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2