Java Code Examples for org.springframework.beans.factory.support.RootBeanDefinition

Following code examples demonstrate how to use org.springframework.beans.factory.support.RootBeanDefinitionfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.beans.factory.support.RootBeanDefinitionand various code implementation of this class.

    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String interfaceName = element.getAttribute("interfaceName");
        String ipAddr = element.getAttribute("ipAddr");
        String protocol = element.getAttribute("protocol");
        String id = element.getAttribute("id");
        RootBeanDefinition definition = new RootBeanDefinition();
        definition.setBeanClass(RpcReference.class);
        definition.setLazyInit(false);
        definition.getPropertyValues().add("interfaceName", interfaceName);
        definition.getPropertyValues().add("ipAddr", ipAddr);
        definition.getPropertyValues().add("protocol", protocol);
        parserContext.getRegistry().registerBeanDefinition(id, definition);
        return definition;
    } 


	public void test() {

		

		String name = "name";
		Object value = new Object();

		

		AttributeAccessor attributeAccessor = new RootBeanDefinition();

		
		attributeAccessor.setAttribute(name, value);

		
		aeq(true, attributeAccessor.hasAttribute(name));
		aeq(1, attributeAccessor.attributeNames().length);
		aeq("name", attributeAccessor.attributeNames()[0]);

		
		aeqr(value, attributeAccessor.getAttribute(name));

		
		attributeAccessor.removeAttribute(name);
		aeq(false, attributeAccessor.hasAttribute(name));

	} 

    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String ipAddr = element.getAttribute("ipAddr");
        String protocol = element.getAttribute("protocol");
        String id = element.getAttribute("id");
        RootBeanDefinition definition = new RootBeanDefinition();
        definition.setBeanClass(RpcRegistery.class);
        definition.setLazyInit(false);
        definition.getPropertyValues().add("ipAddr", ipAddr);
        definition.getPropertyValues().add("protocol", protocol);
        parserContext.getRegistry().registerBeanDefinition(id, definition);
        return definition;
    } 

	public static void load(String name, Class<?> clazz, ParserContext parserContext) {
		RootBeanDefinition beanDefinition = new RootBeanDefinition(clazz);
		beanDefinition.setAutowireCandidate(true);
		beanDefinition.setAutowireMode(AbstractBeanDefinition.DEPENDENCY_CHECK_ALL);
		beanDefinition.setTargetType(clazz);
		parserContext.getRegistry().registerBeanDefinition(name, beanDefinition);
	} 

    public static void main(String[] args) {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        RootBeanDefinition dummyDef = new RootBeanDefinition("com.lujian.springmulti.basic.Dummy");
        factory.registerBeanDefinition("dummy", dummyDef);
    } 

    
    public static void registerInfrastructureBean(BeanDefinitionRegistry beanDefinitionRegistry,
                                                  String beanName,
                                                  Class<?> beanType) {

        if (!beanDefinitionRegistry.containsBeanDefinition(beanName)) {
            RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
            beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
            beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
        }

    } 

    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String interfaceName = element.getAttribute("interfaceName");
        String ref = element.getAttribute("ref");
        String id = element.getAttribute("id");
        RootBeanDefinition definition = new RootBeanDefinition();
        definition.setBeanClass(RpcService.class);
        definition.setLazyInit(false);
        definition.getPropertyValues().add("interfaceName", interfaceName);
        definition.getPropertyValues().add("ref", ref);
        parserContext.getRegistry().registerBeanDefinition(id, definition);
        return definition;
    } 

	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		boolean definition = registry.containsBeanDefinition("bill");
		if (definition) {
			BeanDefinition beanDefinition = new RootBeanDefinition(RainBow.class);
			registry.registerBeanDefinition("rainBow", beanDefinition );
		}
	} 

	public static void main(String[] args) {
		RootBeanDefinition bd=new RootBeanDefinition(People.class);
		RuntimeBeanNameReference reference=new RuntimeBeanNameReference("");
		PropertyValue pv=new PropertyValue("", "");
		bd.getPropertyValues().addPropertyValue(pv);
		bd.setSource("");
		
	} 

Advertisement
Javadoc
A root bean definition represents the merged bean definition that backs a specific bean in a Spring

BeanFactory at runtime. It might have been created from multiple original bean definitions that inherit from each other, typically registered as GenericBeanDefinition GenericBeanDefinitions. A root bean definition is essentially the 'unified' bean definition view at runtime.

Root bean definitions may also be used for registering individual bean definitions in the configuration phase. However, since Spring 2.5, the preferred way to register bean definitions programmatically is the GenericBeanDefinition class. GenericBeanDefinition has the advantage that it allows to dynamically define parent dependencies, not 'hard-coding' the role as a root bean definition. @author Rod Johnson @author Juergen Hoeller @see GenericBeanDefinition @see ChildBeanDefinition

Read More
Advertisement