Search in sources :

Example 1 with AnnotatedBeanDefinitionReader

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

the class DispatcherServletInitializer method getServlet.

@Override
public DispatcherServlet getServlet() {
    DispatcherServlet dispatcherServlet = super.getServlet();
    if (dispatcherServlet == null && isAutoCreateDispatcher()) {
        WebServletApplicationContext context = getApplicationContext();
        BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
        if (!registry.containsBeanDefinition(DispatcherServlet.class)) {
            AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context, registry);
            reader.setEnableConditionEvaluation(false);
            reader.registerBean(DISPATCHER_SERVLET, DispatcherServlet.class);
        }
        dispatcherServlet = context.getBean(DispatcherServlet.class);
        setServlet(dispatcherServlet);
    }
    return dispatcherServlet;
}
Also used : DispatcherServlet(cn.taketoday.web.servlet.DispatcherServlet) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) AnnotatedBeanDefinitionReader(cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader) WebServletApplicationContext(cn.taketoday.web.servlet.WebServletApplicationContext)

Example 2 with AnnotatedBeanDefinitionReader

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

the class HybridContextLoader method loadBeanDefinitions.

@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    // Order doesn't matter: <bean> always wins over @Bean.
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
    new AnnotatedBeanDefinitionReader(context).register(mergedConfig.getClasses());
}
Also used : XmlBeanDefinitionReader(cn.taketoday.beans.factory.xml.XmlBeanDefinitionReader) AnnotatedBeanDefinitionReader(cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader)

Example 3 with AnnotatedBeanDefinitionReader

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

the class AnnotationConfigContextLoader method loadBeanDefinitions.

/**
 * Register classes in the supplied {@link GenericApplicationContext context}
 * from the classes in the supplied {@link MergedContextConfiguration}.
 * <p>Each class must represent a <em>component class</em>. An
 * {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
 * bean definitions.
 * <p>Note that this method does not call {@link #createBeanDefinitionReader}
 * since {@code AnnotatedBeanDefinitionReader} is not an instance of
 * {@link BeanDefinitionReader}.
 *
 * @param context the context in which the component classes should be registered
 * @param mergedConfig the merged configuration from which the classes should be retrieved
 * @see AbstractGenericContextLoader#loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?>[] componentClasses = mergedConfig.getClasses();
    logger.debug("Registering component classes: {}", ObjectUtils.nullSafeToString(componentClasses));
    new AnnotatedBeanDefinitionReader(context).register(componentClasses);
}
Also used : AnnotatedBeanDefinitionReader(cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader)

Example 4 with AnnotatedBeanDefinitionReader

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

the class EnvironmentSystemIntegrationTests method annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR.

@Test
void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.setEnvironment(prodEnv);
    new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
    ctx.refresh();
    assertThat(ctx.containsBean(Constants.DEV_BEAN_NAME)).isFalse();
    assertThat(ctx.containsBean(Constants.PROD_BEAN_NAME)).isTrue();
}
Also used : GenericApplicationContext(cn.taketoday.context.support.GenericApplicationContext) AnnotatedBeanDefinitionReader(cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader) Test(org.junit.jupiter.api.Test)

Example 5 with AnnotatedBeanDefinitionReader

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

the class ClassPathBeanDefinitionScannerScopeIntegrationTests method createContext.

private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) {
    GenericWebServletApplicationContext context = new GenericWebServletApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
    scanner.setIncludeAnnotationConfig(false);
    scanner.setBeanNameGenerator((definition, registry) -> definition.getScope());
    scanner.setScopedProxyMode(scopedProxyMode);
    // Scan twice in order to find errors in the bean definition compatibility check.
    scanner.scan(getClass().getPackage().getName());
    scanner.scan(getClass().getPackage().getName());
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context);
    reader.register(AppConfig1.class);
    context.refresh();
    return context;
}
Also used : ClassPathBeanDefinitionScanner(cn.taketoday.context.annotation.ClassPathBeanDefinitionScanner) AnnotatedBeanDefinitionReader(cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader) GenericWebServletApplicationContext(cn.taketoday.web.context.support.GenericWebServletApplicationContext)

Aggregations

AnnotatedBeanDefinitionReader (cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader)15 ClassPathBeanDefinitionScanner (cn.taketoday.context.annotation.ClassPathBeanDefinitionScanner)4 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)3 BeanNameGenerator (cn.taketoday.beans.factory.support.BeanNameGenerator)2 XmlBeanDefinitionReader (cn.taketoday.beans.factory.xml.XmlBeanDefinitionReader)2 AnnotationBeanNameGenerator (cn.taketoday.context.annotation.AnnotationBeanNameGenerator)2 ScopeMetadataResolver (cn.taketoday.context.loader.ScopeMetadataResolver)2 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)2 GenericWebServletApplicationContext (cn.taketoday.web.context.support.GenericWebServletApplicationContext)2 Test (org.junit.jupiter.api.Test)2 DispatcherServlet (cn.taketoday.web.servlet.DispatcherServlet)1 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)1