Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Proper Usage of the Dependency Injection in MVC

 
Csabba Csurja
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys,

I am curious about your opinion regarding to the proper implementation/usage of DI in Spring MVC:

There are two classes: One Controller which works with a List (for dropdown menu) and there is an another Service class which carries the List elements from DB layer.
How would you inject Service into Contoller in Spring MVC?






My questions:
Is there a way to inject DropDownService.getDropDownItems() elements into DropDownController.dropDownItems List through Dependency Injection in this case? If yes, then how ;-)

Actually, I am looking for the most sophisticated solution, for this reason I am curious about your opinion!

Thanks,
Csaba

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


To me that is the easiest. I am also under the assumption that you see the typo in your DropDownSerivce class and that that class is defined in a Spring configuration, either with @Service or as a ><bean> in your xml.

Mark
 
Csabba Csurja
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark!

Can I say, that I was not able to see the wood for the trees ? ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic