title: Disable spring method caching through external property
body: <p>I configured spring method caching with ehcache and annotation driven configuration.</p>
  
  <p>I would like however to be able to disable it from a configuration file we use in the application.</p>
  
  <p>My first idea was to call <code>net.sf.ehcache.CacheManager.CacheManager()</code> with no arguments if method caching is disabled. This throws exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: loadCaches must not return an empty Collection
  at org.springframework.util.Assert.notEmpty(Assert.java:268)
  at org.springframework.cache.support.AbstractCacheManager.afterPropertiesSet(AbstractCacheManager.java:49)
  </code></pre>
  
  <p>My second idea was to configure the <code>net.sf.ehcache.CacheManager.CacheManager()</code> with default data so that the cache is not used (maxElementsInMemory 0 etc.). But then the cache is still used, which is not what I want.</p>
  
  <p>There is a property <code>net.sf.ehcache.disabled</code> but I do not want do disable hibernate caching that also uses ehcache.</p>
  
  <p><code>Q</code> How can I configure everything to have spring method caching but disable it from my external configuration file? I do not want to modify the application-context nor the code to enable/disable method caching. Only the configuration file we use in the application can be modified.</p>