title: Java based configuration for Ehcache based caching not working
body: <p>I am using java annotation based configuration for initializing ehcache based caching, with Spring 3.1.</p>
  
  <p>Here is the sample code...</p>
  
  <pre><code>@Configuration
  @EnableCaching
  public class EhcacheConfig implements CachingConfigurer {
  
      .....
  
      @Bean
      public CacheManager cacheManager() {
          .....
          EhCacheManagerFactoryBean bean = new EhCacheManagerFactoryBean();
          bean.setCacheManagerName(CACHE_MANAGER);
          bean.setShared(Boolean.TRUE);
          File file = new File(property + Constants.Slash + EHCACHE_XML);
          bean.setConfigLocation(new FileSystemResource(file));
  
          try {
              bean.afterPropertiesSet();
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
          EhCacheCacheManager cm = new EhCacheCacheManager();
          cm.setCacheManager(bean.getObject());
          return cm;
      }
  
      public KeyGenerator keyGenerator() {
          return new DefaultKeyGenerator();
      }
  }
  </code></pre>
  
  <p>There is a valid ehcache.xml with 1 cache declared in it.</p>
  
  <p>This is all the configuration that I have for initializing ehcache with Spring. There is no XML based initialization in the application.</p>
  
  <p>At runtime, I have noticed that cacheManager() is initialized, as expected. After its successful execution, the code fails to complete the initialization by erring out in:</p>
  
  <p>CachingInterceptor.afterPropertiesSet() -></p>
  
  <pre><code>if (this.cacheManager == null) {
      throw new IllegalStateException("'cacheManager' is required");
  }
  </code></pre>
  
  <p>I have done some investigation.</p>
  
  <p>It appears that the problem occurs when CachingInterceptor is being initialized by ProxyCachingConfiguration.</p>
  
  <p>ProxyCachingConfiguration is derived from AbstractCachingConfiguration.</p>
  
  <p>AbstractCachingConfiguration has a method called:</p>
  
  <pre><code>@PostConstruct
  protected void reconcileCacheManager()
  </code></pre>
  
  <p>This method is not invoked. Had it been invoked, the cacheManager instantiated in EhcacheConfig.cacheManger() would have been setup correctly for used by the CacheInterceptor.afterPropertiesSet().</p>
  
  <p>I do not understand the reason why reconcileCacheManager() is not invoked before CacheInterceptor.afterPropertiesSet() is invoked.</p>
  
  <p>Am I missing something? Can some one help me with the problem that I am facing?</p>
  
  <p>Thank you.</p>