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;
}
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());
}
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);
}
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();
}
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;
}
Aggregations