May 8, 2014
I’ve been an old school java programmer for years because I was too lazy to learn new things and technologies. Then I realized that I’m a programmer and programmers needs to learn new technologies every couple of months just to get to the trend so you wont left behind the market. Then I learned about the dependency injections. Before I inject my dependencies using the old fashion way, create a bean and reference it to the other bean, now there’s a newer way to inject a bean, but this post is about injecting collections.
Here’s how to inject a java collection in your spring configuration files.
1. Inject a Map collection.
Initialize first your map collection.
You can now inject your map collection in your java file.
@Resource(name="mapCollection") private Map mapCollection;
2. Inject a List or Set collection.
You can now inject your list or set in your java file.
@Resource(name="listCollection") private List listCollection; // List or Set
3. Inject a Property object
You can now inject your list in your java file.
@Resource(name="props") private Properties props;