Spring フレームワークのコミットに関連するhttps://github.com/spring-projects/spring-framework/commit/5aefcc802ef05abc51bbfbeb4a78b3032ff9eee3
初期化は、 afterPropertiesSet()からafterSingletonsInstantiated( )までの後の段階に設定されます。
要するに:これにより、 @PostConstruct ユースケースで使用するときにキャッシュが機能しなくなります。
より長いバージョン:これにより、使用するケースが防止されます
methodB で @Cacheable を使用して serviceB を作成する
@PostConstruct を使用して serviceA を作成し、serviceB.methodB を呼び出します
@Component public class ServiceA{ @Autowired private ServiceB serviceB; @PostConstruct public void init() { List<String> list = serviceB.loadSomething(); }
これにより、現在 org.springframework.cache.interceptor.CacheAspectSupport が初期化されていないため、結果がキャッシュされません。
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
// check whether aspect is enabled
// to cope with cases where the AJ is pulled in automatically
if (this.initialized) {
//>>>>>>>>>>>> NOT Being called
Class<?> targetClass = getTargetClass(target);
Collection<CacheOperation> operations = getCacheOperationSource().getCacheOperations(method, targetClass);
if (!CollectionUtils.isEmpty(operations)) {
return execute(invoker, new CacheOperationContexts(operations, method, args, target, targetClass));
}
}
//>>>>>>>>>>>> Being called
return invoker.invoke();
}
私の回避策は、初期化メソッドを手動で呼び出すことです。
@Configuration
public class SomeConfigClass{
@Inject
private CacheInterceptor cacheInterceptor;
@PostConstruct
public void init() {
cacheInterceptor.afterSingletonsInstantiated();
}
これはもちろん私の問題を解決しますが、2回呼び出されるだけで副作用がありますか(意図したとおりに1回のマニュアルと1回のフレームワークによる)
私の質問は次のとおりです: