以下を機能させる方法: - @Cacheable アノテーションでキャッシュする必要があるメソッドを持つ Spring Bean - キャッシュのキーを作成する別の Spring Bean (KeyCreatorBean)。
したがって、コードは次のようになります。
@Inject
private KeyCreatorBean keyCreatorBean;
@Cacheable(value = "cacheName", key = "{@keyCreatorBean.createKey, #p0}")
@Override
public List<Examples> getExamples(ExampleId exampleId) {
...
ただし、上記のコードは機能しません。次の例外が発生します。
Caused by: org.springframework.expression.spel.SpelEvaluationException:
EL1057E:(pos 2): No bean resolver registered in the context to resolve access to bean 'keyCreatorBean'