title: @Component beans override @Bean ones for collection autowiring
body: <p>I've got a very simple spring boot test application.</p>
  <p>It has just a Dog class and the @SpringBootApplication annotated one.
  I create two beans of Dog and everything runs as expected.</p>
  <pre class="lang-java prettyprint-override"><code>
  public class Dog {
      
      public String name;
      
      public Dog() {
          this(&quot;noname&quot;);
      }
  
      public Dog(String name) {
          this.name = name;
      }
  
      public String toString() {
          return name;
      }
  }
  
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  public class DemoApplication {
  
      @Autowired
      private List&lt;Dog&gt; dogs;
      
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
      
      @Bean
      CommandLineRunner runner1() {
          return args -&gt; {
              for (Dog d : dogs) {
                  System.out.println(d);
              }
          };
      }
  
      
      @Bean
      Dog laika() {
          return new Dog(&quot;laika&quot;);
      }
  
      @Bean
      Dog lassie() {
          return new Dog(&quot;lassie&quot;);
      }
  }
  </code></pre>
  <p>Outputs:</p>
  <pre><code>laika
  lassie
  </code></pre>
  <p>However now I add a @Component annotation to Dog class, expecting that now I'll got three beans of type Dog and that's what it seems to happen if I print all beans with another CommandLineRunner like this one:</p>
  <pre class="lang-java prettyprint-override"><code>    @Bean
        public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
          return args -&gt; {
            System.out.println(&quot;Let's inspect the beans provided by Spring Boot:&quot;);
            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
              System.out.println(beanName);
            }
          };
      }
  </code></pre>
  <p>Outputs:</p>
  <pre><code>Let's inspect the beans provided by Spring Boot:
  applicationAvailability
  applicationTaskExecutor
  commandLineRunner
  demoApplication
  dog
  laika
  lassie
  lifecycleProcessor
  ...
  </code></pre>
  <p>Yet, when I use my first CommandLineRunner for printing out the contents of my Dog list, the only output that I get is:</p>
  <pre><code>noname
  </code></pre>
  <p>It seems like @Component beans have made the beans declared by @Bean dissapear for collection injection. I observe the same behaviour with any beans, for example if I declare more CommandLineRunners in an independent @Component class, everyone is ran, but when I @Autowire'd them in a list, only the ones declared with @Component are injected.</p>
  <p>Nevertheless, I can still use the other Dog beans. For example, if I annotate Laika bean with @Primary, it's the one that will be injected as a method argument, but nothing changes regarding the @Autowire'd collection.</p>