List of usage examples for org.springframework.beans.factory.support RootBeanDefinition RootBeanDefinition
public <T> RootBeanDefinition(@Nullable Class<T> beanClass, @Nullable Supplier<T> instanceSupplier)
From source file:gov.nih.nci.cabig.ctms.web.tabs.DefaultTabConfigurerTest.java
private RootBeanDefinition createTestBeanDef(int id) { return new RootBeanDefinition(TestBean.class, new MutablePropertyValues(Collections.singletonMap("id", id))); }
From source file:org.iterx.miru.spring.beans.TestSpringBeanFactory.java
public void testBeanAccessors() { DefaultListableBeanFactory springFactory; RootBeanDefinition beanDefinition;// w w w .j a v a 2 s .c o m BeanFactory beanFactory; Object bean; springFactory = new DefaultListableBeanFactory(); beanFactory = new SpringBeanFactory(springFactory); assertFalse(beanFactory.containsBean("bean")); assertNull(beanFactory.getBean("bean")); beanDefinition = new RootBeanDefinition(SpringBeanFactory.class, 0); beanDefinition.setSingleton(true); springFactory.registerBeanDefinition("bean", beanDefinition); assertTrue(beanFactory.containsBean("bean")); assertNotNull(beanFactory.getBean("bean")); assertNotNull((bean = beanFactory.getBean("bean"))); assertTrue(bean instanceof SpringBeanFactory); assertNull((bean = beanFactory.getBeanOfType(TestCase.class))); assertNotNull((bean = beanFactory.getBeanOfType(BeanFactory.class))); assertTrue(bean instanceof BeanFactory); assertNull((bean = beanFactory.getBeanOfType(new Class[] { TestCase.class }))); assertNotNull( (bean = beanFactory.getBeanOfType(new Class[] { BeanFactory.class, BeanWrapperSupport.class }))); assertTrue(bean instanceof BeanFactory && bean instanceof BeanWrapperSupport); assertNull(beanFactory.getBeanOfType(new Class[] { BeanFactory.class, TestCase.class })); assertTrue(beanFactory.isSingleton("bean")); beanDefinition.setSingleton(false); springFactory.registerBeanDefinition("bean-prototype", beanDefinition); assertFalse(beanFactory.isSingleton("bean-prototype")); }
From source file:org.springmodules.cache.config.CacheProxyFactoryBeanParser.java
/** * Creates and registers a <code>{@link CacheProxyFactoryBean}</code> by * parsing the given XML element.//from w ww .ja v a 2 s .co m * * @param element * the XML element to parse * @param parserContext * the registry of bean definitions * @param propertySource * contains common properties for the different cache setup * strategies * @throws IllegalStateException * if the "proxy" tag does not contain any reference to an existing * bean or if it does not contain a bean definition * * @see AbstractCacheSetupStrategyParser#parseCacheSetupStrategy(Element, * ParserContext, CacheSetupStrategyPropertySource) */ protected void parseCacheSetupStrategy(Element element, ParserContext parserContext, CacheSetupStrategyPropertySource propertySource) { Object target = getBeanReferenceParser().parse(element, parserContext); RootBeanDefinition cacheProxyFactoryBean = new RootBeanDefinition(CacheProxyFactoryBean.class, propertySource.getAllProperties()); cacheProxyFactoryBean.getPropertyValues().addPropertyValue("target", target); String id = element.getAttribute("id"); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(id, cacheProxyFactoryBean); }
From source file:org.iterx.miru.support.spring.bean.factory.TestSpringBeanFactory.java
public void testBeanAccessors() { DefaultListableBeanFactory springFactory; RootBeanDefinition beanDefinition;//from w w w .j a v a 2 s .c om BeanFactory beanFactory; Object bean; springFactory = new DefaultListableBeanFactory(); beanFactory = new SpringBeanFactory(springFactory); assertFalse(beanFactory.containsBean("bean")); assertNull(beanFactory.getBean("bean")); beanDefinition = new RootBeanDefinition(SpringBeanFactory.class, 0); beanDefinition.setSingleton(true); springFactory.registerBeanDefinition("bean", beanDefinition); assertTrue(beanFactory.containsBean("bean")); assertNotNull(beanFactory.getBean("bean")); assertNotNull((bean = beanFactory.getBean("bean"))); assertTrue(bean instanceof SpringBeanFactory); assertNull((bean = beanFactory.getBeanOfType(TestCase.class))); assertNotNull((bean = beanFactory.getBeanOfType(BeanFactory.class))); assertTrue(bean instanceof BeanFactory); assertNull((bean = beanFactory.getBeanOfType(new Class[] { TestCase.class }))); assertNotNull( (bean = beanFactory.getBeanOfType(new Class[] { BeanFactory.class, BeanWrapperAware.class }))); assertTrue(bean instanceof BeanFactory && bean instanceof BeanWrapperAware); assertNull(beanFactory.getBeanOfType(new Class[] { BeanFactory.class, TestCase.class })); assertTrue(beanFactory.isSingleton("bean")); beanDefinition.setSingleton(false); springFactory.registerBeanDefinition("bean-prototype", beanDefinition); assertFalse(beanFactory.isSingleton("bean-prototype")); }
From source file:org.springmodules.cache.config.AbstractCacheProviderFacadeParser.java
/** * Parses the specified XML element which contains the properties of the * <code>{@link org.springmodules.cache.provider.CacheProviderFacade}</code> * to register in the given registry of bean definitions. * // w ww . j a v a2 s .c o m * @param element * the XML element to parse * @param parserContext * the parser context * @throws IllegalStateException * if the value of the property <code>serializableFactory</code> * is not equal to "NONE" or "XSTREAM" * * @see BeanDefinitionParser#parse(Element, ParserContext) */ public final BeanDefinition parse(Element element, ParserContext parserContext) throws IllegalStateException { String id = element.getAttribute("id"); // create the cache provider facade Class clazz = getCacheProviderFacadeClass(); MutablePropertyValues propertyValues = new MutablePropertyValues(); RootBeanDefinition cacheProviderFacade = new RootBeanDefinition(clazz, propertyValues); propertyValues.addPropertyValue(parseFailQuietlyEnabledProperty(element)); propertyValues.addPropertyValue(parseSerializableFactoryProperty(element)); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(id, cacheProviderFacade); doParse(id, element, registry); return null; }
From source file:org.springmodules.cache.config.MethodMapInterceptorsParser.java
private void registerCachingInterceptor(String cachingInterceptorId, BeanDefinitionRegistry registry, CacheSetupStrategyPropertySource propertySource) { MutablePropertyValues propertyValues = new MutablePropertyValues(); RootBeanDefinition cachingInterceptor = new RootBeanDefinition(MethodMapCachingInterceptor.class, propertyValues);/*from w w w . j ava 2 s. co m*/ propertyValues.addPropertyValue(propertySource.getCacheKeyGeneratorProperty()); propertyValues.addPropertyValue(propertySource.getCacheProviderFacadeProperty()); propertyValues.addPropertyValue(propertySource.getCachingListenersProperty()); propertyValues.addPropertyValue(propertySource.getCachingModelsProperty()); registry.registerBeanDefinition(cachingInterceptorId, cachingInterceptor); }
From source file:org.springmodules.cache.config.MethodMapInterceptorsParser.java
private void registerFlushingInterceptor(String flushingInterceptorId, BeanDefinitionRegistry registry, CacheSetupStrategyPropertySource propertySource) { MutablePropertyValues propertyValues = new MutablePropertyValues(); RootBeanDefinition flushingInterceptor = new RootBeanDefinition(MethodMapFlushingInterceptor.class, propertyValues);/* w ww.j a v a2 s . c o m*/ propertyValues.addPropertyValue(propertySource.getCacheProviderFacadeProperty()); propertyValues.addPropertyValue(propertySource.getFlushingModelsProperty()); registry.registerBeanDefinition(flushingInterceptorId, flushingInterceptor); }
From source file:com.taobao.itest.spring.context.SpringContextManager.java
public static void registerBeanDefinition(Field field, ApplicationContext applicationContext) { @SuppressWarnings("deprecation") RootBeanDefinition beanDefinition = new RootBeanDefinition(field.getType(), true); beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) (applicationContext .getAutowireCapableBeanFactory()); defaultListableBeanFactory.registerBeanDefinition(field.getName(), beanDefinition); }
From source file:org.springmodules.cache.config.AbstractMetadataAttributesParser.java
private void registerCachingInterceptor(BeanDefinitionRegistry registry, CacheSetupStrategyPropertySource propertySource) { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(propertySource.getCacheKeyGeneratorProperty()); propertyValues.addPropertyValue(propertySource.getCacheProviderFacadeProperty()); propertyValues.addPropertyValue(propertySource.getCachingListenersProperty()); propertyValues.addPropertyValue(propertySource.getCachingModelsProperty()); RootBeanDefinition cachingInterceptor = new RootBeanDefinition(MetadataCachingInterceptor.class, propertyValues);//from w w w . j a v a 2 s .c om configureCachingInterceptor(propertyValues, registry); String beanName = BeanName.CACHING_INTERCEPTOR; registry.registerBeanDefinition(beanName, cachingInterceptor); }
From source file:org.springmodules.cache.config.AbstractMetadataAttributesParser.java
private void registerFlushingInterceptor(BeanDefinitionRegistry registry, CacheSetupStrategyPropertySource propertySource) { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(propertySource.getCacheProviderFacadeProperty()); propertyValues.addPropertyValue(propertySource.getFlushingModelsProperty()); RootBeanDefinition flushingInterceptor = new RootBeanDefinition(MetadataFlushingInterceptor.class, propertyValues);// w w w. j av a 2s . co m configureFlushingInterceptor(propertyValues, registry); String beanName = BeanName.FLUSHING_INTERCEPTOR; registry.registerBeanDefinition(beanName, flushingInterceptor); }