use of cn.taketoday.beans.factory.support.BeanDefinitionRegistry in project today-framework by TAKETODAY.
the class ConditionalTests method testConditionalOnResource.
@Test
public void testConditionalOnResource() throws Exception {
try (StandardApplicationContext context = new StandardApplicationContext()) {
ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
processor.setPropertiesLocation("info.properties");
processor.postProcessEnvironment();
context.scan("cn.taketoday.context.condition");
BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
Assertions.assertFalse(registry.containsBeanDefinition(ConditionalOnResource_.class));
Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource__.class));
Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource___.class));
Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource____.class));
}
}
use of cn.taketoday.beans.factory.support.BeanDefinitionRegistry in project today-framework by TAKETODAY.
the class AbstractServletWebServer method prepareInitialize.
@Override
protected void prepareInitialize() {
super.prepareInitialize();
WebServerApplicationContext context = obtainApplicationContext();
Class<?> mainApplicationClass = getMainApplicationClass();
if (mainApplicationClass != null) {
ServletSecurity servletSecurity = mainApplicationClass.getAnnotation(ServletSecurity.class);
if (servletSecurity != null) {
BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
if (registry.containsBeanDefinition(ServletSecurityElement.class)) {
log.info("Multiple: [{}] Overriding its bean definition", ServletSecurityElement.class.getName());
}
context.unwrap(BeanDefinitionRegistrar.class).registerSingleton(new ServletSecurityElement(servletSecurity));
}
}
addDefaultServlet();
addJspServlet();
}
use of cn.taketoday.beans.factory.support.BeanDefinitionRegistry in project today-framework by TAKETODAY.
the class ClassPathMapperScanner method postProcessBeanDefinition.
protected void postProcessBeanDefinition(BeanDefinitionHolder holder) {
AbstractBeanDefinition definition = (AbstractBeanDefinition) holder.getBeanDefinition();
String beanClassName = definition.getBeanClassName();
log.debug("Creating MapperFactoryBean with name '{}' and '{}' mapperInterface", definition.getBeanName(), beanClassName);
// the mapper interface is the original class of the bean
// but, the actual class of the bean is MapperFactoryBean
// issue #59
definition.getConstructorArgumentValues().addGenericArgumentValue(beanClassName);
definition.setBeanClass(mapperFactoryBeanClass);
PropertyValues propertyValues = definition.getPropertyValues();
propertyValues.add("addToConfig", addToConfig);
// Attribute for MockitoPostProcessor
// https://github.com/mybatis/spring-boot-starter/issues/475
definition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, beanClassName);
boolean explicitFactoryUsed = false;
if (StringUtils.hasText(sqlSessionFactoryBeanName)) {
propertyValues.add("sqlSessionFactory", RuntimeBeanReference.from(sqlSessionFactoryBeanName));
explicitFactoryUsed = true;
} else if (sqlSessionFactory != null) {
propertyValues.add("sqlSessionFactory", sqlSessionFactory);
explicitFactoryUsed = true;
}
if (StringUtils.hasText(sqlSessionTemplateBeanName)) {
if (explicitFactoryUsed) {
log.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
}
propertyValues.add("sqlSessionTemplate", RuntimeBeanReference.from(sqlSessionTemplateBeanName));
explicitFactoryUsed = true;
} else if (sqlSessionTemplate != null) {
if (explicitFactoryUsed) {
log.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
}
propertyValues.add("sqlSessionTemplate", sqlSessionTemplate);
explicitFactoryUsed = true;
}
if (!explicitFactoryUsed) {
log.debug("Enabling autowire by type for MapperFactoryBean with name '{}'.", definition.getBeanName());
definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
}
definition.setLazyInit(lazyInitialization);
if (BeanDefinition.SCOPE_SINGLETON.equals(definition.getScope()) && defaultScope != null) {
definition.setScope(defaultScope);
}
if (!definition.isSingleton()) {
BeanDefinitionRegistry registry = delegate.getRegistry();
BeanDefinitionHolder proxyHolder = ScopedProxyUtils.createScopedProxy(holder, registry, true);
if (registry.containsBeanDefinition(proxyHolder.getBeanName())) {
registry.removeBeanDefinition(proxyHolder.getBeanName());
}
registry.registerBeanDefinition(proxyHolder.getBeanName(), proxyHolder.getBeanDefinition());
}
}
use of cn.taketoday.beans.factory.support.BeanDefinitionRegistry in project today-framework by TAKETODAY.
the class AnnotationBeanNamePopulatorTests method generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName.
@Test
public void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() {
BeanDefinitionRegistry registry = new DefaultBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.class);
String beanName = this.beanNamePopulator.populateName(bd, registry);
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
String expectedGeneratedBeanName = this.beanNamePopulator.buildDefaultBeanName(bd);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
use of cn.taketoday.beans.factory.support.BeanDefinitionRegistry in project today-framework by TAKETODAY.
the class AnnotationBeanNamePopulatorTests method generateBeanNameFromComposedControllerAnnotationWithBlankName.
@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
// SPR-11360
BeanDefinitionRegistry registry = new DefaultBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
String beanName = this.beanNamePopulator.populateName(bd, registry);
String expectedGeneratedBeanName = this.beanNamePopulator.buildDefaultBeanName(bd);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
Aggregations