Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13438

Doc: @Configuration class accepts overloaded factory methods for same bean

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.2.1
    • Fix Version/s: 4.2.3
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I do not expect a single @Configuration class accepting several beans with the same name. I guess it should follow the same contract in XML where one could not define in the same XML 2 bean with the same id.

      Here is a test demonstrating the behavior. I guess there is no know knowing which bean has been accepted, and this would change from one environment to another.

      package blasd.apex.server.datastore.tuple;
      
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.test.context.ContextConfiguration;
      import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
      
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(classes = { TestSameConfDiffBeanSamename.class })
      @Configuration
      public class TestSameConfDiffBeanSamename {
      	@Bean
      	public String firstBean() {
      		return "youpi";
      	}
      
      	@Bean
      	public Integer someBeanName(String someString) {
      		return someString.length();
      	}
      
      	@Bean
      	public Integer someBeanName() {
      		return 1;
      	}
      
      	@Autowired
      	Integer someInteger;
      
      	@Test
      	public void wonderingWhichIntegerWillArrive() {
      		System.out.println(someInteger);
      	}
      }
      

      Regards

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              blasd Benoit Lacelle
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 37 weeks, 1 day ago