title: @Cacheable condition using application properties
body: <p>I'm trying to use Redis with Spring's <code>@Cacheable</code> but need to conditionally turn caching on or off based on a Spring Boot style application property. My first attempt doesn't seem to work.</p>
  
  <p>The application.properties file:</p>
  
  <pre><code>auth.token-cache-enabled=false
  </code></pre>
  
  <p>The properties class:</p>
  
  <pre><code>@Component
  @ConfigurationProperties(prefix = "auth")
  public class AuthProperties {
      public boolean tokenCacheEnabled;
      ...
  }
  </code></pre>
  
  <p>The service method annotation:</p>
  
  <pre><code>@Cacheable(key = "#token", condition = "@authProperties.tokenCacheEnabled()")
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'authProperties' at org.springframework.expression.spel.ast.BeanReference.getValueInternal(BeanReference.java:48)
  </code></pre>
  
  <p>Does anyone have an idea what the problem is or if there's another way to achieve this?</p>