Results 1 to 3 of 3

Thread: spring 3.1 bean name alias bug

  1. #1
    Join Date
    Dec 2012
    Posts
    8

    Default spring 3.1 bean name alias bug

    the test code will go to a infinite loop. found the class org.springframework.core.SimpleAliasRegistry had a bug.

    config:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    	<bean id="a" class="test.TestAlias" />
    	<bean id="b" class="test.TestAlias" />
    	<bean id="c" class="test.TestAlias" />
    	<bean id="d" class="test.TestAlias" />
    	<bean id="e" class="test.TestAlias" />
    	<alias name="a" alias="b"/>
    	<alias name="b" alias="c"/>
    	<alias name="c" alias="d"/>
    	<alias name="d" alias="e"/>
    	<alias name="e" alias="c"/>
    </beans>

    java code:
    Code:
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    public class TestAlias {
    	public static void main(String[] args) {
    		String config="config.xml";
    		FileSystemXmlApplicationContext context=new FileSystemXmlApplicationContext(config);
    		String[] als=context.getAliases("e");
    		for(String str:als){
    			System.out.println(str);
    		}
    		context.close();
    	}
    }
    Last edited by shenzhenguy; Dec 7th, 2012 at 01:16 AM.

  2. #2
    Join Date
    Dec 2009
    Location
    India
    Posts
    108

    Red face

    looks like you mean that
    Code:
    while(true) {
    //some business code
    }
    is going to infinite loop. Of course it is cause it is coded that way.

  3. #3
    Join Date
    Dec 2012
    Posts
    8

    Default

    I think spring should avoid the circle references, and he actually want to do this,but failed.
    if the last line of config file is : <alias name="e" alias="d"/> or <alias name="e" alias="a"/> , Spring will throw Exception when in creation.
    but for : <alias name="e" alias="c"/> or <alias name="e" alias="b"/> or <alias name="d" alias="b"/>,Spring cannot find the circle references, lead to getAliases() run into infinite loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •