This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Spring and the fly likes How to pass a collection as argument to a constructor using Spring based dependency injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to pass a collection as argument to a constructor using Spring based dependency injection" Watch "How to pass a collection as argument to a constructor using Spring based dependency injection" New topic
Author

How to pass a collection as argument to a constructor using Spring based dependency injection

Nikhilesh Reddy Chaduvula
Greenhorn

Joined: Mar 21, 2013
Posts: 6
Hi
I am using Mongodb

How to pass a collection as constructor argument to the above constructor using spring.
I don't want to use string as argument but i want to pass a collection from spring (Anything is fine but xml is preferred)
My xml goes something like this

Let me know if anyone has already done it.

Thanks,
Nikhil
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1682
    
    7



You would need to then create a bean with id = myMongoCollection and of class = com.mongodb.DBCollection of course the that bean would have yet another constructor-arg ref of a bean of type com.mongodb.DB and a string. You would continue this pattern until you just had simple types. Something like this is much easier to do with Java Config but you said you prefer XML.


[How To Ask Questions][Read before you PM me]
Nikhilesh Reddy Chaduvula
Greenhorn

Joined: Mar 21, 2013
Posts: 6
Hi Bill Gorder,

Can you please cite an example of java Config based approach which would really help me.

Thanks,
Nkhil
 
 
subject: How to pass a collection as argument to a constructor using Spring based dependency injection
 
jQuery in Action, 3rd edition