use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class AbstractBeanFactory method getMergedBeanDefinition.
/**
* Return a RootBeanDefinition for the given bean, by merging with the
* parent if the given bean's definition is a child bean definition.
* @param beanName the name of the bean definition
* @param bd the original bean definition (Root/ChildBeanDefinition)
* @param containingBd the containing bean definition in case of inner bean,
* or {@code null} in case of a top-level bean
* @return a (potentially merged) RootBeanDefinition for the given bean
* @throws BeanDefinitionStoreException in case of an invalid bean definition
*/
protected RootBeanDefinition getMergedBeanDefinition(String beanName, BeanDefinition bd, BeanDefinition containingBd) throws BeanDefinitionStoreException {
synchronized (this.mergedBeanDefinitions) {
RootBeanDefinition mbd = null;
// Check with full lock now in order to enforce the same merged instance.
if (containingBd == null) {
mbd = this.mergedBeanDefinitions.get(beanName);
}
if (mbd == null) {
if (bd.getParentName() == null) {
// Use copy of given root bean definition.
if (bd instanceof RootBeanDefinition) {
mbd = ((RootBeanDefinition) bd).cloneBeanDefinition();
} else {
mbd = new RootBeanDefinition(bd);
}
} else {
// Child bean definition: needs to be merged with parent.
BeanDefinition pbd;
try {
String parentBeanName = transformedBeanName(bd.getParentName());
if (!beanName.equals(parentBeanName)) {
pbd = getMergedBeanDefinition(parentBeanName);
} else {
BeanFactory parent = getParentBeanFactory();
if (parent instanceof ConfigurableBeanFactory) {
pbd = ((ConfigurableBeanFactory) parent).getMergedBeanDefinition(parentBeanName);
} else {
throw new NoSuchBeanDefinitionException(parentBeanName, "Parent name '" + parentBeanName + "' is equal to bean name '" + beanName + "': cannot be resolved without an AbstractBeanFactory parent");
}
}
} catch (NoSuchBeanDefinitionException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, "Could not resolve parent bean definition '" + bd.getParentName() + "'", ex);
}
// Deep copy with overridden values.
mbd = new RootBeanDefinition(pbd);
mbd.overrideFrom(bd);
}
// Set default singleton scope, if not configured before.
if (!StringUtils.hasLength(mbd.getScope())) {
mbd.setScope(RootBeanDefinition.SCOPE_SINGLETON);
}
// definition will not have inherited the merged outer bean's singleton status.
if (containingBd != null && !containingBd.isSingleton() && mbd.isSingleton()) {
mbd.setScope(containingBd.getScope());
}
// instance of the bean, or at least have already created an instance before.
if (containingBd == null && isCacheBeanMetadata()) {
this.mergedBeanDefinitions.put(beanName, mbd);
}
}
return mbd;
}
}
use of org.springframework.beans.factory.BeanFactory in project ignite by apache.
the class SpringTransactionManagerContextInjectionTest method testBeanInjectionUsingConfigPath.
/**
* @throws Exception If failed.
*/
public void testBeanInjectionUsingConfigPath() throws Exception {
BeanFactory factory = new AnnotationConfigApplicationContext(TestPathConfiguration.class);
Ignite grid = IgnitionEx.grid("springInjectionTest");
IgniteConfiguration cfg = grid.configuration();
LifecycleBean[] beans = cfg.getLifecycleBeans();
assertEquals(2, beans.length);
TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean) beans[0];
TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean) beans[1];
bean1.checkState();
bean2.checkState();
}
use of org.springframework.beans.factory.BeanFactory in project ignite by apache.
the class GridSpringCacheManagerSelfTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
BeanFactory factory = new ClassPathXmlApplicationContext("org/apache/ignite/cache/spring/spring-caching.xml");
svc = (GridSpringCacheTestService) factory.getBean("testService");
dynamicSvc = (GridSpringDynamicCacheTestService) factory.getBean("dynamicTestService");
svc.reset();
dynamicSvc.reset();
}
use of org.springframework.beans.factory.BeanFactory in project geronimo-xbean by apache.
the class SpringInitialContextFactory method loadContext.
protected BeanFactory loadContext(Resource resource, String key) {
synchronized (cache) {
BeanFactory answer = (BeanFactory) cache.get(key);
if (answer == null) {
answer = createContext(resource);
cache.put(key, answer);
}
return answer;
}
}
use of org.springframework.beans.factory.BeanFactory in project geronimo-xbean by apache.
the class ComponentTest method test.
protected void test(String file) {
BeanFactory f = new ClassPathXmlApplicationContext(file);
ContainerBean container = (ContainerBean) f.getBean("container");
assertNotNull(container);
assertNotNull(container.getBeans());
assertEquals(1, container.getBeans().length);
}
Aggregations