title: Spring : registering bean by private method
body: <p>I am configuring spring security,below is my code-  </p>
  
  <pre><code>@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.userDetailsService(customUserDetailsService).passwordEncoder(encoder);
  }
  
  @Bean(name="encoder")
  public BCryptPasswordEncoder getPasswordEncoder(){
      return new BCryptPasswordEncoder();
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
  ...
  }
  </code></pre>
  
  <p>As soon as I applied @Autowire on-</p>
  
  <pre><code>@Override
  @Autowire
      protected void configure(HttpSecurity http) throws Exception {
      ...
      }
  </code></pre>
  
  <p>This throws exception no bean of type 'HttpSecurity' in container,this is expected.</p>
  
  <p>But when I applied <code>@Autowire</code> on-</p>
  
  <pre><code>@Override
  @Autowire
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(customUserDetailsService).passwordEncoder(encoder);
      }
  </code></pre>
  
  <p>There is no exception?<strong>how this <code>AuthenticationManagerBuilder</code> bean is in bean factory?</strong></p>
  
  <p>when I changed my bean registration with private method like this-</p>
  
  <pre><code>@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.userDetailsService(customUserDetailsService).passwordEncoder(getPasswordEncoder());
  }
  
  @Bean(name="encoder")
  private BCryptPasswordEncoder getPasswordEncoder(){
      return new BCryptPasswordEncoder();
  }
  </code></pre>
  
  <p><strong>This is throwing exception,method cant be private.Why so?</strong></p>