Hi All, I am new to spring, we have a requirement that we would like to change our java data structures declaratively (configurable).
i.e , we have implemented data feeds, queues using PriorityQueue, Synchronized Hashmaps, vectors etc
will spring framework give me an option to inject (instantiate) these collections classes dynamically. I mean , if we need to change to PriorityBlockingQueue, and change Hashmaps to hashtable and vectors to Synchronized ArrayLists
i would greatly appreciate if someone can give some pointers if this is supported by spring framework.
Spring can help ease the pain. Here are some suggestions:
1. Program to interfaces; use interfaces or abstract types for your method/constructor parameters. Spring can inject any type of object as long as it is assignment compatible with the receiving method/constructor parameter's type. If you do this, it will be easier to switch out implementations.
2. Take advantage of Spring's built-in collection injection support for injecting lists, maps, sets, and properties.
3. If things start to get ugly, try using the Adapter pattern. Create an Adapter that can accept one or more of the natively supported collections and then inject the adapter into the target class. The target class then uses the adapter to get whatever type of collection it needs. The adapter does the transformation from simple collection to custom collection. This should probably be considered as a last resort. Strive to keep your code simple using 1 & 2 above.