Announcement Announcement Module
Collapse
No announcement yet.
spring 3.1 bean name alias bug Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:16 AM.

  • #2
    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.

    Comment


    • #3
      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.

      Comment

      Working...
      X