Hi all, I am learning spring 3.x. In method injection section they mentioned its usage and said that method injection should not be used because it causes a dependency on spring. Should we use it or not? If no, then is there any other alternative?
chaitanya karthikk wrote:Hi all, I am learning spring 3.x. In method injection section they mentioned its usage and said that method injection should not be used because it causes a dependency on spring. Should we use it or not? If no, then is there any other alternative?
Thank you.
You have to show context. I think you are taking it out of context and it makes no sense. How would it cause a dependency on Spring. Who says? What exactly are you pointing to. Where in the documentation does it say that.
Spring is a Dependency Injection container at its heart, where you do DI with either constructors, methods or instance variables, all are good choices and not one of them ties you to Spring.
Mark Spritzler wrote:
You have to show context. I think you are taking it out of context and it makes no sense. How would it cause a dependency on Spring. Who says? What exactly are you pointing to. Where in the documentation does it say that.
Spring is a Dependency Injection container at its heart, where you do DI with either constructors, methods or instance variables, all are good choices and not one of them ties you to Spring.
Mark
While using method injection we have to make method call to getBean(bean) which causes the dependency. In the documentation they also mentioned that our code should not contain a method call getBean(bean) at all. However I don't know the alternate approach for this method call because I am still reading bean scopes. Please refer this section.