In the post dependency injection in Spring we have already gone through the concept of dependency injection, in this post we’ll see in details one of the type of dependency injection- Setter dependency injection in Spring . For another type of dependency injection, Constructor dependency injection check this post- Constructor Dependency Injection in Spring Spring Setter dependency injection In setter based DI Spring container calls setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean. For configuring setter based dependencies you can use XML configuration as well as annotations. We’ll see examples of doing it using both of these ways. Spring Setter dependency injection Example In the example there is a class to place orders called Order and purchase can be done from an online store or a retail store. In Order class dependencies for the properties are injected using setter dependency injection.
Java, Spring, Web development tutorials with examples