Sus*_*ath 0 spring-mvc spring-el spring-cache
我正在使用 Spring Caching 框架和 redis。以下是我使用的 Cacheable
@Cacheable(value = "oauth2token", key="#value + #type")
public OAuth2Token findOneByValueAndType(String value, String type);
Run Code Online (Sandbox Code Playgroud)
我只是想创建一个我知道的密钥。这给出了错误
14:20:21,199 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/veip-web].[Resteasy]] (http-/0.0.0.0:8080-63) JBWEB000236: Servlet.service() for servlet Resteasy threw exception: org.springframework.expression.spel.SpelEvaluationException: EL1030E:(pos 0): The operator 'ADD' is not supported between objects of type 'null' and 'null'
Run Code Online (Sandbox Code Playgroud)
因为当我没有将 key 指定为流时。
@Cacheable(value = "oauth2token")
public OAuth2Token findOneByValueAndType(String value, String type);
Run Code Online (Sandbox Code Playgroud)
我可以看到生成了一个疯狂的密钥。我需要知道密钥,因为稍后我需要CachePut更新相同的项目。
我也尝试跟随。
@Cacheable(value = "oauth2token", key="#type.contact(#value)")
public OAuth2Token findOneByValueAndType(String value, String type);
Run Code Online (Sandbox Code Playgroud)
Spring 抱怨那个时候#type是空的。
这里有什么问题。
您可能没有每个参数名称的运行时信息(#value 不知道)。更安全的方法是使用始终有效的#por#a别名。应该做的伎俩。key="#p0 + #p1"
话虽如此,我不会那样做。如果您在另一个带注释的方法中重用键,我将实现KeyGenerator为一个 bean 并在需要处理这两个值的方法中传递该 bean 的引用。这样您就可以共享(和测试)该代码并避免重复。
| 归档时间: |
|
| 查看次数: |
5999 次 |
| 最近记录: |