I have a Spring configuration class like this where I need to configure 2 different Queue:
@Configuration
public class DataQueue {
/**
* Queue to store the {@link SlowVars} read from the PLC
* @return the queue
*/
@Bean
Set<JsonNode> slowVarsQueue() {
return new CopyOnWriteArraySet<>();
}
/**
* Queue to store the {@link JsonNode} events
* @return the queue
*/
@Bean
Set<JsonNode> eventsQueue() {
return new CopyOnWriteArraySet<>();
}
}
In the class where I need to use one queue I wrote:
@Log4j2
@RestController
@AllArgsConstructor
public class EventsApiImpl implements EventsApi {
private Set<JsonNode> eventsQueue;
private MariaEventService mariaEventService;
private EventManipulationService eventManipulationService;
private ObjectMapper mapper;
// lots of methods
}
unfortunately Springs raise an error starting:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean
with name 'slowVarsApiImpl': Unsatisfied dependency expressed through constructor parameter 0:
No qualifying bean of type 'java.util.Set[com.fasterxml.jackson.databind.JsonNode]' available:
expected single matching bean but found 2: slowVarsQueue,eventsQueue
The two beans has different names one is slowVarsQueue
and the other is eventsQueue
, why Spring complain ?