0

Consider following snippet, I am trying to call a method of propertiesContainer which would be used as a key.

@Cacheable(value = EhCacheManagerApi.CACHE_X_TOKEN, key = ("#{propertiesContainer.getId()}"))
public String getToken(PropertiesContainer propertiesContainer)

I cannot seem to figure out the correct spel expression for key, current format gives me:

org.springframework.expression.spel.SpelParseException: EL1043E:(pos 1): Unexpected token. Expected 'identifier' but was 'lcurly({)'

Before I tried key = ("#propertiesContainer.id") and key = ("#propertiesContainer.getId()")

propertiesContainer is an interface which has method getId returning String.

So presumably this is not the same as bean method invocation with SpEL?

Aubergine
  • 5,862
  • 19
  • 66
  • 110

2 Answers2

0

Did you try the pure expression without the parenthesis:

@Cacheable(value = EhCacheManagerApi.CACHE_X_TOKEN, key="propertiesContainer.id")

This works for me in Spring 4.3.3 where PropertiesContainer is an interface with a getId() method.

Also, you might need to use #p0.id instead of the method parameter name if you don't have debug info in your compiled code. See the accepted answer here but that would give you a different error I suspect.

Community
  • 1
  • 1
tchambers
  • 456
  • 3
  • 5
0

Could you please try this

    @Cacheable(value = EhCacheManagerApi.CACHE_X_TOKEN, key = "#{T(java.lang.String).format('%d-%d', #propertiesContainer.id)}")
Divagar Haldurai
  • 399
  • 2
  • 3
  • 11