Java Code Examples for org.springframework.beans.factory.config.RuntimeBeanNameReference

Following code examples demonstrate how to use org.springframework.beans.factory.config.RuntimeBeanNameReferencefrom 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.config.RuntimeBeanNameReferenceand various code implementation of this class.

	public void test() {

		

		

		Object bean = new Object();

		RuntimeBeanNameReference beanMetadataElement = new RuntimeBeanNameReference("name");
		beanMetadataElement.setSource(bean);

		aeqr(bean, beanMetadataElement.getSource());
	} 


	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
		super.doParse(element, parserContext, builder);
		AbstractBeanDefinition bd = builder.getBeanDefinition();
		MutablePropertyValues propertyValues = bd.getPropertyValues();
		String beanName = element.getAttribute("bean");
		RuntimeBeanNameReference rbnr = new RuntimeBeanNameReference(beanName);
		propertyValues.add("carId", rbnr);
	} 

    public static void main(String[] args) {
        
        
        
        RuntimeBeanNameReference ref = new RuntimeBeanNameReference("beanName");
        
        RuntimeBeanReference refBean = new RuntimeBeanReference("beanName");
        
        
    } 

	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("");
		
	} 

    public void staticApplicationContextTithDI(){
        StaticApplicationContext applicationContext = new StaticApplicationContext(  );
        applicationContext.registerSingleton( "hello" ,HelloPerson.class);
        BeanDefinition beanDefinition = new RootBeanDefinition( HelloPerson.class );
        beanDefinition.getPropertyValues().addPropertyValue( "name","허윤호" );
        beanDefinition.getPropertyValues().addPropertyValue( "hello",new RuntimeBeanNameReference( "hello" ) );
        applicationContext.registerBeanDefinition( "helloPerson", beanDefinition );
        Hello hello =applicationContext.getBean( "helloPerson", Hello.class );
        assertThat( hello.sayHello(),is("hello!!! 허윤호") );
    } 

Advertisement
Javadoc
Immutable placeholder class used for a property value object when it's a reference to another bean n

ame in the factory, to be resolved at runtime. @author Juergen Hoeller @since 2.0 @see RuntimeBeanReference @see BeanDefinition#getPropertyValues() @see org.springframework.beans.factory.BeanFactory#getBean

Read More
Advertisement