Java Code Examples for org.springframework.beans.factory.support.AbstractBeanDefinition#setBeanClass()
The following examples show how to use
org.springframework.beans.factory.support.AbstractBeanDefinition#setBeanClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testExplicitScopeInheritanceForChildBeanDefinitions() { String theChildScope = "bonanza!"; RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); AbstractBeanDefinition child = BeanDefinitionBuilder.childBeanDefinition("parent").getBeanDefinition(); child.setBeanClass(TestBean.class); child.setScope(theChildScope); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child"); assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope()); }
Example 2
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 6 votes |
private BeanDefinition buildSessionFactoryBeanDefinition(Element element, String name, BeanDefinitionParserDelegate beanDefinitionParserDelegate, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SESSION_FACTORY_SUFFIX); beanDefinition.setBeanClass(LocalSessionFactoryBean.class); beanDefinition.setParentName(SESSION_FACTORY_PARENT_BEAN_NAME); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dataSource", new RuntimeBeanReference(name + DATA_SOURCE_SUFFIX)); if (element.hasAttribute(TABLE_PREFIX_NAME) && !StringUtil.isEmpty(element.getAttribute(TABLE_PREFIX_NAME))) { AbstractBeanDefinition namingStrategyBeanDefinition = new GenericBeanDefinition(); String randomBeanName = UUID.randomUUID().toString(); namingStrategyBeanDefinition.setAttribute(ID_ATTRIBUTE, randomBeanName); namingStrategyBeanDefinition.setBeanClass(HibernateNamingStrategy.class); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); mutablePropertyValues.add("prefix", element.getAttribute(TABLE_PREFIX_NAME)); namingStrategyBeanDefinition.setPropertyValues(mutablePropertyValues); beanDefinitionRegistry.registerBeanDefinition(randomBeanName, namingStrategyBeanDefinition); propertyValues.addPropertyValue("namingStrategy", new RuntimeBeanReference(randomBeanName)); } beanDefinition.setPropertyValues(propertyValues); beanDefinitionParserDelegate.parsePropertyElements(element, beanDefinition); return beanDefinition; }
Example 3
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testExplicitScopeInheritanceForChildBeanDefinitions() throws Exception { String theChildScope = "bonanza!"; RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); AbstractBeanDefinition child = BeanDefinitionBuilder.childBeanDefinition("parent").getBeanDefinition(); child.setBeanClass(TestBean.class); child.setScope(theChildScope); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child"); assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope()); }
Example 4
Source File: GroovyBeanDefinitionWrapper.java From lams with GNU General Public License v2.0 | 6 votes |
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(this.clazz); if (!CollectionUtils.isEmpty(this.constructorArgs)) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : this.constructorArgs) { cav.addGenericArgumentValue(constructorArg); } bd.setConstructorArgumentValues(cav); } if (this.parentName != null) { bd.setParentName(this.parentName); } this.definitionWrapper = new BeanWrapperImpl(bd); return bd; }
Example 5
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testExplicitScopeInheritanceForChildBeanDefinitions() { String theChildScope = "bonanza!"; RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); AbstractBeanDefinition child = BeanDefinitionBuilder.childBeanDefinition("parent").getBeanDefinition(); child.setBeanClass(TestBean.class); child.setScope(theChildScope); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child"); assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope()); }
Example 6
Source File: GroovyBeanDefinitionWrapper.java From java-technology-stack with MIT License | 6 votes |
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(this.clazz); if (!CollectionUtils.isEmpty(this.constructorArgs)) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : this.constructorArgs) { cav.addGenericArgumentValue(constructorArg); } bd.setConstructorArgumentValues(cav); } if (this.parentName != null) { bd.setParentName(this.parentName); } this.definitionWrapper = new BeanWrapperImpl(bd); return bd; }
Example 7
Source File: GroovyBeanDefinitionWrapper.java From spring-analysis-note with MIT License | 6 votes |
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(this.clazz); if (!CollectionUtils.isEmpty(this.constructorArgs)) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : this.constructorArgs) { cav.addGenericArgumentValue(constructorArg); } bd.setConstructorArgumentValues(cav); } if (this.parentName != null) { bd.setParentName(this.parentName); } this.definitionWrapper = new BeanWrapperImpl(bd); return bd; }
Example 8
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testScopeInheritanceForChildBeanDefinitions() { RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope("bonanza!"); AbstractBeanDefinition child = new ChildBeanDefinition("parent"); child.setBeanClass(TestBean.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); BeanDefinition def = factory.getMergedBeanDefinition("child"); assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope()); }
Example 9
Source File: MqBeanParser.java From zxl with Apache License 2.0 | 5 votes |
protected void buildRabbitTemplateBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition rabbitTemplateBeanDefinition = new GenericBeanDefinition(); rabbitTemplateBeanDefinition.setBeanClass(RabbitTemplate.class); ConstructorArgumentValues rabbitTemplateConstructorArgumentValues = new ConstructorArgumentValues(); rabbitTemplateConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName)); rabbitTemplateBeanDefinition.setConstructorArgumentValues(rabbitTemplateConstructorArgumentValues); beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitTemplateBeanDefinition); }
Example 10
Source File: JobDrivenBeanDefinitionParser.java From niubi-job with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); MutablePropertyValues propertyValues = new MutablePropertyValues(); beanDefinition.setBeanClass(SpringContextJobDriver.class); propertyValues.addPropertyValue("packagesToScan", element.getAttribute("packagesToScan")); beanDefinition.setPropertyValues(propertyValues); beanDefinition.setInitMethodName("init"); BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry()); return beanDefinition; }
Example 11
Source File: MqBeanParser.java From zxl with Apache License 2.0 | 5 votes |
protected void buildRabbitAdminBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition rabbitAdminBeanDefinition = new GenericBeanDefinition(); rabbitAdminBeanDefinition.setBeanClass(RabbitAdmin.class); ConstructorArgumentValues rabbitAdminConstructorArgumentValues = new ConstructorArgumentValues(); rabbitAdminConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName)); rabbitAdminBeanDefinition.setConstructorArgumentValues(rabbitAdminConstructorArgumentValues); beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitAdminBeanDefinition); }
Example 12
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testScopeInheritanceForChildBeanDefinitions() { RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope("bonanza!"); AbstractBeanDefinition child = new ChildBeanDefinition("parent"); child.setBeanClass(TestBean.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); BeanDefinition def = factory.getMergedBeanDefinition("child"); assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope()); }
Example 13
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testScopeInheritanceForChildBeanDefinitions() throws Exception { RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope("bonanza!"); AbstractBeanDefinition child = new ChildBeanDefinition("parent"); child.setBeanClass(TestBean.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); BeanDefinition def = factory.getMergedBeanDefinition("child"); assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope()); }
Example 14
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildDataSourceBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + DATA_SOURCE_SUFFIX); beanDefinition.setBeanClass(SimpleDataSource.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("name", name); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example 15
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildSqlSessionFactoryBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SQL_SESSION_FACTORY_SUFFIX); beanDefinition.setBeanClass(SqlSessionFactoryBean.class); beanDefinition.setParentName(SQL_SESSION_FACTORY_PARENT_BEAN_NAME); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dataSource", new RuntimeBeanReference(name + DATA_SOURCE_SUFFIX)); propertyValues.add("mapperLocations", MAPPER_LOCATIONS_PREFIX + name + MAPPER_LOCATIONS_SUFFIX); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example 16
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildSqlSessionTemplateBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SQL_SESSION_TEMPLATE_SUFFIX); beanDefinition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(name + SQL_SESSION_FACTORY_SUFFIX)); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); return beanDefinition; }
Example 17
Source File: MqBeanParser.java From zxl with Apache License 2.0 | 5 votes |
protected void buildConnectionFactoryBeanDefinition(String beanName, String host, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition connectionFactoryBeanDefinition = new GenericBeanDefinition(); connectionFactoryBeanDefinition.setBeanClass(CachingConnectionFactory.class); if (!StringUtil.isEmpty(host)) { MutablePropertyValues connectionFactoryPropertyValues = new MutablePropertyValues(); connectionFactoryPropertyValues.add("host", host); connectionFactoryBeanDefinition.setPropertyValues(connectionFactoryPropertyValues); } beanDefinitionRegistry.registerBeanDefinition(beanName, connectionFactoryBeanDefinition); }
Example 18
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildHibernateTransactionManagerBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX); beanDefinition.setBeanClass(HibernateTransactionManager.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("sessionFactory", new RuntimeBeanReference(name + SESSION_FACTORY_SUFFIX)); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example 19
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildHibernateAdviceBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + HIBERNATE_ADVICE_SUFFIX); beanDefinition.setBeanClass(TransactionInterceptor.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("transactionManager", new RuntimeBeanReference(name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX)); propertyValues.add("transactionAttributeSource", new RuntimeBeanReference(name + TRANSACTION_ATTRIBUTE_SOURCE_SUFFIX)); beanDefinition.setPropertyValues(propertyValues); return beanDefinition; }
Example 20
Source File: GridFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Gets test Spring application context with single {@link StringBuilder} bean * with name "myBean" and value "Test string". * * @return Spring application context. */ private ApplicationContext getTestApplicationContext() { AbstractBeanDefinition def = new GenericBeanDefinition(); def.setBeanClass(StringBuilder.class); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.addGenericArgumentValue("Test string"); def.setConstructorArgumentValues(args); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("myBean", def); return ctx; }