title: Changing Autowired bean type unexpectedly changes value?
body: <p>I've tried to create an Application and ran into some funky behavior. First, I'll run through my setup. Here's my configuration class:</p>
  
  <blockquote>
    <p>ProblemApp.java</p>
  </blockquote>
  
  <pre><code>@SpringBootApplication
  public class ProblemApp
  {
      public static void main(String[] args)
      {
          var context = SpringApplication.run(ProblemApp.class);
          var tblController = context.getBean(TableController.class);
          tblController.printTable();
      }
      @Bean
      public TableController getTableController()
      {
          return new TableController();
      }
      @Bean("componentTable")
      public String[] getComponentTable() //weird
      {
          return new String[] { "application.components" };
      }
  }
  </code></pre>
  
  <p>Here's my component:</p>
  
  <blockquote>
    <p>TableController.java</p>
  </blockquote>
  
  <pre><code>@Controller
  public class TableController
  {
      private static final Logger log = LoggerFactory.getLogger(TableController.class);
  
      @Autowired
      private String[] componentTable; //weird
  
      public void printTable()
      {
          log.info("Component table: " + Arrays.deepToString(componentTable));
      }
  }
  </code></pre>
  
  <p>This is my <code>module-info.java</code> and directory structure:</p>
  
  <pre><code>module problem.application
  {
      exports application;
      exports controller;
  
      opens controller to spring.core;
      opens application to spring.core;
  
      requires spring.context;
      requires spring.boot;
      requires spring.boot.autoconfigure;
      requires spring.beans;
      requires spring.core;
      requires java.sql;
      requires org.slf4j;
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>src/main/java/
      application
          ProblemApp.java
      controller
          TableController.java
      module-info.java
  src/test/java/ is empty
  src/main/resources/ is empty
  </code></pre>
  
  <p>This is the pom.xml I use to retrieve dependencies (using Maven in Spring Tool Suite 4):</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;problem.application&lt;/groupId&gt;
      &lt;artifactId&gt;problem-app&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;Problematic application&lt;/name&gt;
      &lt;description&gt;An application with some problems&lt;/description&gt;
  
      &lt;build&gt;
          &lt;sourceDirectory&gt;src/main/java&lt;/sourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;release&gt;12&lt;/release&gt;
                      &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent --&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.8.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>This code, as it is, works as I expected it to. The relevant part of the output is: </p>
  
  <pre class="lang-none prettyprint-override"><code>2019-09-11 10:55:21.351  INFO 21060 --- [           main] controller.TableController               : 
  Component table: [application.components]
  </code></pre>
  
  <p>Now, I tried to change the type of Bean <code>componentTable</code> to <code>Object[]</code>. In ProblemApp:</p>
  
  <pre><code>@Bean("componentTable")
  public Object[] getComponentTable() //weird
  {
      return new Object[] { "application.components" };
  }
  </code></pre>
  
  <p>In TableController:</p>
  
  <pre><code>@Autowired
  private Object[] componentTable; //weird
  </code></pre>
  
  <p>Suddenly, the output of the program changes drastically:</p>
  
  <pre class="lang-none prettyprint-override"><code>2019-09-11 10:57:05.630  INFO 10156 --- [           main] controller.TableController               : 
  Component table: [org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor@b40bb6e, 
  org.springframework.context.annotation.CommonAnnotationBeanPostProcessor@3f28bd56, 
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor@3276732, 
  org.springframework.context.annotation.ConfigurationClassPostProcessor@f74e835, 
  org.springframework.context.support.PropertySourcesPlaceholderConfigurer@48c35007, 
  org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar@4b3c354a, 
  org.springframework.context.event.EventListenerMethodProcessor@31e3250d, 
  org.springframework.context.event.DefaultEventListenerFactory@19fe4644, 
  application.ProblemApp$$EnhancerBySpringCGLIB$$7e1f363f@21d8bcbe,
  ...
  // more Spring-looking things and then environment information
  </code></pre>
  
  <p>What is going on here?</p>