Java – spring auto assembly of parameterized collections
Hello everyone, thank you for your help
I have a problem that spring cannot automatically assemble parameterized member variables of arrayblockingqueue type
This is java code:
@Controller public class SomeController { @Autowired private ArrayBlockingQueue<SomeCustomType> myQueue; }
And in the spring configuration XML:
<bean id="myQueue" class="java.util.concurrent.ArrayBlockingQueue"> <constructor-arg value="10"/> </bean>
Specifying a type (somecustomtype) for arrayblockingqueue seems confusing. Spring cannot find a match and does not perform automatic assembly
Any ideas on how to make it work? I know I can create my own wrapper class (around arrayblockingqueue). This class is not parameterized, but I'd rather not know if there is a better way to solve this problem
Solution
If you try to connect collections automatically using annotations, @ resource is used instead of @ Autowired
To satisfy the @ Autowired collection dependency, the IOC container looks for elements of the correct type to build such a collection In other words, it does not look for the collection itself, but builds the collection from other beans
For more information, refer to the spring documentation, for example here.