title: Using FileChangedReloadingStrategy and it's alternatives
body: <p>To dynamically reload my app configuration, I decided to try out Apache commons 
  <a href="https://commons.apache.org/proper/commons-configuration/javadocs/v1.10/apidocs/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.html" rel="nofollow noreferrer">FileChangedReloadingStrategy</a></p>
  
  <p>I am doing Ldap Authentication using Spring Security and before using <code>FileChangedReloadingStrategy</code>, I was keeping a single instance of <code>LdapTemplate</code>, like:</p>
  
  <pre><code>@Component
  public class LdapAuthenticationProvider implements AuthenticationProvider{  
  
  
      private LdapTemplate ldapTemplate;  
      private LdapContextSource contextSource;    
  
      @PostConstruct
      public void init() {        
          contextSource = new LdapContextSource();
          contextSource.setUrl(LDAP_CONFIG_BASE_URL);
          contextSource.setAnonymousReadOnly(LDAP_CONFIG_IS_ANONYMOUS);
          contextSource.afterPropertiesSet();
          ldapTemplate = new LdapTemplate(contextSource);
      }   
  
  @Override
      public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  // use ldapTemplate to do authentication
  }
  </code></pre>
  
  <p>However, since now I am trying to provide a dynamic config change, I have to create a new ldap connection each time (so that modified config,if any, could be used). But this will affect performance.</p>
  
  <pre><code>@Autowired
  private AppConfig config;
  
  @Override
      public Authentication authenticate(Authentication authentication) throws AuthenticationException {
          contextSource = new LdapContextSource();
          contextSource.setUrl(config.getProperty("LDAP_CONFIG_BASE_URL"));
          contextSource.setAnonymousReadOnly(Boolean.parseBoolean(config.getProperty("LDAP_CONFIG_IS_ANONYMOUS")));
          contextSource.afterPropertiesSet();
          ldapTemplate = new LdapTemplate(contextSource);
  
              // Do auth related stuff
  }
  </code></pre>
  
  <p>So my question is, can this trade off between performance and providing dynamic config be avoided? Is there a non-Springboot way to refresh beans?</p>
  
  <p><strong>NOTE:</strong>: I found out that with Springboot, you can use Spring-cloud in which there is way to refresh beans but I am not using Springboot and could not find proper documentation to use  spring-cloud without Springboot so I stuck to Apache's FileChangedReloadingStrategy.</p>
  
  <p><strong>EDIT:</strong>
  I am facing the performance issue in which ldap connection pool sometimes becomes full and I get connection time out error due to this.</p>