title: Can I use Spring's caching features without the annotations?
body: <p>I'm developing a module I was planning on using <a href="http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/cache.html" rel="nofollow noreferrer">Spring's declarative caching</a> to handle.  I wrote a number of methods using the cache</p>
  
  <pre><code>@Override
  @Cacheable("businessUnitCache")
  public BusinessUnit getBusinessUnit(String businessUnitId){
  </code></pre>
  
  <p>I was planning to provide a classpath beans file and classpath <a href="http://ehcache.org/documentation/configuration/index" rel="nofollow noreferrer">eh-cache configuration</a> to provide the functionality without requiring consuming projects to know the internals of my implementation and which methods need to be cached (many of these methods they'd never access <em>directly</em>).</p>
  
  <p>However, reading the question <a href="https://stackoverflow.com/q/8658789/16487">Using Spring cache annotation in multiple modules</a> and it's answers this is obviously going to cause a problem is any of the consuming projects use Spring cache annotations as well.  I was hopeful that Sprint would fail silently if there was no declared cache matching an annotation, but it fails with the error:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Cannot find cache named [businessUnitCache] for CacheableOperation[public</p>
  </blockquote>
  
  <p>Leading me to the conclusion I can't use the cache annotations (which conflicts with my original conclusion from the question <a href="https://stackoverflow.com/q/8834993/16487">Is it possible to use multiple ehcache.xml (in different projects, same war)?</a>.  My testing backs this up.</p>
  
  <p>So: <strong>Is it possible to declare the caching separately from the implementation classes, preferably in xml?</strong>  This would allow me to prepare an additional file with the caching rules, and replace the cache manager name using standard spring property replacement (I'm already doing something similar with the datasource)?  Unfortunately the <a href="http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/cache.html" rel="nofollow noreferrer">refernece documentation</a> only describes the annotation based configuration.</p>