title: Why is bean only created when main method is placed at the beginning of the class?
body: <p>I have a spring application whose entry point is the following:</p>
  
  <pre><code>@SpringBootApplication
  @EnableAutoConfiguration(exclude = { HypermediaAutoConfiguration.class })
  public class Application {
  
      @Bean(name = "firstApi")
      private static RestApiProxy getFirstApi(@Value("${midtier.host}") String host,
              @Value("${midtier.port}") int port) {
          String baseURI = "/cesmidtier/api";
          return new FirstApi("http", host, port, baseURI, new RequestContextHolder());
      }
  
      @Bean(name = "secondApi")
      private static RestApiProxy getSecondApi(@Value("${yodlee.host}") String host,
              @Value("${yodlee.port}") int port, @Value("${yodlee.baseURI}") String baseURI,
              @Value("${proxy}") String proxyURI) {
          return new SecondApi("https", host, port, baseURI, proxyURI);
      }
  
      @Bean(name = "thirdApi")
      private static RestApiProxy getThirdApi(@Value("${amexopen.host}") String host,
              @Value("${amexopen.port}") int port, @Value("${proxy}") String proxyURI) {
          return new ThirdApi("https", host, port, "/", proxyURI);
      }
  
      @Bean
      @Profile("Test-Mocked")
      public CommonsRequestLoggingFilter logger() {
          CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
          filter.setIncludeQueryString(true);
          filter.setIncludePayload(true);
          filter.setMaxPayloadLength(5120);
          return filter;
      }
  
      @Bean
      @Autowired
      @ConditionalOnProperty(name = "security.enabled", havingValue = "true")
      public AuthorizeHelper authorizeHelper(final ProfileService profileService, final JWTHandler jwtHandler,
              final APIGatewayHandler apiGatewayHandler,
              @Value("${security.permittedClientServices}") String[] permittedClientServices) {
          System.out.println("######################################### 111111111111 ");
          return new DefaultAuthorizeHelper(profileService, jwtHandler, apiGatewayHandler, permittedClientServices);
      }
  
      @Bean
      @ConditionalOnProperty(name = "security.enabled", havingValue = "false")
      public AuthorizeHelper authorizeHelper() {
          System.out.println("######################################### 2222222222222 ");
          return new NullAuthorizeHelper();
      }
  
      public static void main(String[] args) {
          SLF4JBridgeHandler.removeHandlersForRootLogger();
          SLF4JBridgeHandler.install();
  
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>As you can see the class has 2 methods with similar name:</p>
  
  <p>(i)  authorizeHelper(...) with arguments</p>
  
  <p>(ii) authorizeHelper()    without arguments</p>
  
  <p>When I start the application with security=false, then everything work as expected (the application goes into the second authorizeHelper method, the one without arguments).</p>
  
  <p><strong>Problem:</strong>
  But, when I start the application with security=true, the application does not create the expected bean (it does NOT go into the first authorizeHelper method, the one with arguments).</p>
  
  <p><strong>Solutions</strong> I've found:</p>
  
  <p>1.If I name both methods differently, then this problem disappears.</p>
  
  <p>2.If I put the main method at the beginning of the class (as opposed to the end of the class) then the problem also disappears!</p>
  
  <p><strong>Question</strong> <em>Why does the position of the main method seem to play a role in the bean instantiation when both authorizeHelper method have the same name ?</em></p>