1

Spring をバージョン 4 にアップグレードした後、カスタム キー ジェネレーターが機能しなくなりました。移行前は、「生成」メソッドをオーバーライドするコードが実行されていましたが、Spring 4.0.5 に移行した後、コードはまったく実行されません。代わりに、SimpleKeyGenerator が常に実行されることがわかりました。これは春のバグですか?以前のバージョンで使用していたように、generate メソッドを独自のコードでオーバーライドできないのはなぜですか?

ルート コンテキストからのサンプル:

<cache:annotation-driven key-generator="cacheKeyGenerator" />
<bean id="cacheKeyGenerator" class="com.poalim.xp.general.cache.CacheKeyGenerator"/>

Java キー生成のサンプル (移行前)

public class CacheKeyGenerator extends DefaultKeyGenerator implements ApplicationContextAware {
public Object generate(Object target, Method method, Object... params) { 
    return  method.getName() + super.generate(target, method, params); 
}

}

移行後のサンプルコード

public class CacheKeyGenerator extends SimpleKeyGenerator implements ApplicationContextAware {
public Object generate(Object target, Method method, Object... params) { 
    return  method.getName() + super.generate(target, method, params); 
}

}

追加情報: コードをデバッグした後、「生成」メソッドが呼び出されるたびに、SimpleKeyGenerator でのみ実行され、カスタム CacheKeyGenerator クラスでは実行されないことがわかりました。理由を理解しようとしたので、デバッグを行いました。デバッグ中に、プライベート プロパティを持つ org.springframework.cache.interceptor.CacheAspectSupport クラスがあることがわかりました。このクラスには keyGenerator プロパティのセッター メソッドがあり、コンテキストが開始されると、このセッター メソッドがカスタム CacheKeyGenerator で呼び出されることがわかったので、構成は正しく、構成に問題はないと結論付けました。また、キーの生成が必要な場合、keyGenerator プロパティが「CacheKeyGenerator」の値を「失い」、「

4

1 に答える 1