I'm using a CacheManager in a Spring Boot application with SCOPE_REQUEST scope.
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
I'm also using Kafka for communication between microservices. Actually I'm receiving an event through a Kafka consumer and I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.cacheManager': Scope 'request' is not active for the current thread;
...
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread?
It's clear that the CacheManager bean is missing on the listener thread. My goal is to have let the Spring Boot/Kafka framework to create the mean for each consumed Kafka events just as it's for the web requests. I have no idea how I could achive that, could someone help me ?
Thank you so much, Have a nice day!