I have created to Hazelcast map config in one instance. I have a bean method inside config which sends separate maps in 2 different methods. Class CacheService has a field which will be injected by any one of those methods.
I am trying to use Qualifier annotation to get instance of CacheService, but I need one CacheService instance to hold a variable from first type bean method return value and second instance to have the second bean return value. PS: I use lombok for auto constructor and injection How can I achieve this?
I tried using Qualifiers in the @bean annotation method and create two seperate class for CacheService with qualifiers inside for fields, which didn't work.
Config Class
@Bean
public IMap<String, Object> mainCache(HazelcastInstance hazelcastInstance) {
return hazelcastInstance.getMap(mainCache);
}
@Bean
public IMap<String, Object> secCache(HazelcastInstance hazelcastInstance) {
return hazelcastInstance.getMap(SecondaryCache);
}
Class that uses bean method's value
@Service
@RequiredArgsConstructor
public class CacheService {
//Value that needs to be dynamic based on the qualifier
private final IMap<String, Object> cache;
public void put(String key, Object value) {
cache.put(key, value);
}
public Object get(String key) {
return cache.get(key);
}
public <T> T get(String key, Class<T> type) {
return type.cast(cache.get(key));
}
}
Class with a problem
@RequiredArgsConstructor
@EnableAspectJAutoProxy
public class CacheCalculationInterceptor {
//I need this instance with CacheService's variable IMap as returned by mainCache method of config class
private final CacheService mainCacheService;
//I need this instance with CacheService's variable IMap as returned by secCache method of config class
private final CacheService secCacheService;
As I mentioned in comment I need 2 instances of CacheService class that has fields with different values from 2 different bean method. But I am getting "Parameter 0 of constructor in CacheService required a single bean, but 2 were found:"