<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jsyrjala" rel="nofollow">Juha Syrjälä</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9578?redirect=false" rel="nofollow">SPR-9578</a></strong> and commented</p>
<p dir="auto">I am trying to use a result of method call to a spring bean as a part of the cache key, but that doesn't seem to work.</p>
<p dir="auto"><code class="notranslate">@Inject</code><br>
private KeyCreatorBean keyCreatorBean;</p>
<p dir="auto"><code class="notranslate">@Cacheable</code>(value = "cacheName", key = "{<code class="notranslate">@keyCreatorBean</code>.createKey, #p0}")<br>
<code class="notranslate">@Override</code><br>
public List&lt;Examples&gt; getExamples(ExampleId exampleId) {</p>
<p dir="auto">Results in this kind of stack trace:</p>
<p dir="auto">org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 1): Field or property 'keyCreatorBean' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject'<br>
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)<br>
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:72)<br>
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)<br>
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)<br>
at org.springframework.expression.spel.ast.InlineList.getValueInternal(InlineList.java:86)<br>
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)<br>
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)<br>
at org.springframework.cache.interceptor.ExpressionEvaluator.key(ExpressionEvaluator.java:80)<br>
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.generateKey(CacheAspectSupport.java:464)</p>
<hr>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://stackoverflow.com/q/11396911/1431" rel="nofollow">http://stackoverflow.com/q/11396911/1431</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398188024" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18385" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18385/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18385">#18385</a> Cacheable condition SpEL cannot invoke bean methods (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398115719" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13512" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13512/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13512">#13512</a> <code class="notranslate">@Cachable</code> condition should allow referencing return value</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398192832" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18804" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18804/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18804">#18804</a> Allow <code class="notranslate">@Cacheable</code> method to return java.util.Optional variant of cached value</li>
</ul>
<p dir="auto">10 votes, 12 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=alza" rel="nofollow">Alex</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2294?redirect=false" rel="nofollow">SPR-2294</a></strong> and commented</p>
<p dir="auto">I have a class 'MyBean' with a property 'myMap' of type java.util.Map. Spring allows me to configure an instance of this class as follows, using mapped properties:</p>
<p dir="auto">&lt;bean id="myBean" class="com.foo.MyBean"&gt;<br>
&lt;property name="myMap[foo]" value="a" /&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">This works fine.</p>
<p dir="auto">However, I have an application where the map keys need to be mapped property names, e.g "foo.bar[0]". i.e. the map entry key itself contains the "[" and "]" character:</p>
<p dir="auto">&lt;bean id="myBean" class="com.foo.MyBean"&gt;<br>
&lt;property name="myMap[foo.bar[0]]" value="a" /&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">When I call toString() on the myMap property after Spring has instantiated the bean, this is the result:</p>
<p dir="auto">{foo.bar[0=a}</p>
<p dir="auto">As you can see, the key for this map entry is missing the closing "]" character.</p>
<p dir="auto">There appears to be a bug in the string parsing of the mapped property name?</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.2.8</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398059780" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5976" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5976/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5976">#5976</a> Handle nested brackets in a map keys (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 1 watchers</p>