use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class ControllerAdviceBeanTests method equalsHashCodeAndToStringForBeanName.
@Test
public void equalsHashCodeAndToStringForBeanName() {
String beanName = "myBean";
BeanFactory beanFactory = mock(BeanFactory.class);
given(beanFactory.containsBean(beanName)).willReturn(true);
ControllerAdviceBean bean1 = new ControllerAdviceBean(beanName, beanFactory);
ControllerAdviceBean bean2 = new ControllerAdviceBean(beanName, beanFactory);
assertEqualsHashCodeAndToString(bean1, bean2, beanName);
}
use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.
the class BeanFactoryDataSourceLookupTests method testLookupWhereBeanFactoryYieldsNonDataSourceType.
@Test
public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception {
final BeanFactory beanFactory = mock(BeanFactory.class);
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow(new BeanNotOfRequiredTypeException(DATASOURCE_BEAN_NAME, DataSource.class, String.class));
BeanFactoryDataSourceLookup lookup = new BeanFactoryDataSourceLookup(beanFactory);
assertThatExceptionOfType(DataSourceLookupFailureException.class).isThrownBy(() -> lookup.getDataSource(DATASOURCE_BEAN_NAME));
}
use of cn.taketoday.beans.factory.BeanFactory in project today-framework by TAKETODAY.
the class ConfigurationPropertiesBinder method register.
static void register(BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(FACTORY_BEAN_NAME)) {
BeanDefinition definition = BeanDefinitionBuilder.rootBeanDefinition(ConfigurationPropertiesBinder.Factory.class).getBeanDefinition();
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(ConfigurationPropertiesBinder.FACTORY_BEAN_NAME, definition);
}
if (!registry.containsBeanDefinition(BEAN_NAME)) {
BeanDefinition definition = BeanDefinitionBuilder.rootBeanDefinition(ConfigurationPropertiesBinder.class, () -> ((BeanFactory) registry).getBean(FACTORY_BEAN_NAME, ConfigurationPropertiesBinder.Factory.class).create()).getBeanDefinition();
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(ConfigurationPropertiesBinder.BEAN_NAME, definition);
}
}
use of cn.taketoday.beans.factory.BeanFactory in project today-framework by TAKETODAY.
the class BeanNameAutoProxyCreator method isSupportedBeanName.
/**
* Determine if the bean name for the given bean class matches one of the names
* in the configured list of supported names.
*
* @param beanClass the class of the bean to advise
* @param beanName the name of the bean
* @return {@code true} if the given bean name is supported
* @see #setBeanNames(String...)
*/
private boolean isSupportedBeanName(Class<?> beanClass, String beanName) {
if (this.beanNames != null) {
boolean isFactoryBean = FactoryBean.class.isAssignableFrom(beanClass);
for (String mappedName : this.beanNames) {
if (isFactoryBean) {
if (!mappedName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
continue;
}
mappedName = mappedName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
}
if (isMatch(beanName, mappedName)) {
return true;
}
}
BeanFactory beanFactory = getBeanFactory();
String[] aliases = (beanFactory != null ? beanFactory.getAliases(beanName) : NO_ALIASES);
for (String alias : aliases) {
for (String mappedName : this.beanNames) {
if (isMatch(alias, mappedName)) {
return true;
}
}
}
}
return false;
}
use of cn.taketoday.beans.factory.BeanFactory in project today-framework by TAKETODAY.
the class AspectAutoProxyCreator method getFactory.
@NonNull
private BeanFactory getFactory() {
BeanFactory beanFactory = getBeanFactory();
Assert.state(beanFactory != null, "No BeanFactory available");
return beanFactory;
}
Aggregations