• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

spring - declarative collections  RSS feed

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

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.

Many thanks,
Abdul Aleem
Posts: 13454
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!