• DI,  spring,  Spring Basics,  Spring Interview Questions

    Different types of dependency injection(DI)

    There are two types of dependency injection: setter injection and constructor injection. Setter Injection: Normally in all the java beans, we will use setter and getter method to set and get the value of property as follows: public class namebean {String name; public void setName(String a) {name = a; }public String getName() {return name; }} We will create an instance of the bean ‘namebean’ (say bean1) and set property as bean1.setName(“tom”); Here in setter injection, we will set the property ‘name’ in spring configuration file as showm below:<bean id=”bean1″ class=”namebean”><property name=”name” ><value>tom</value></property></bean>The subelement <value> sets the ‘name’ property by calling the set method as setName(“tom”); This process is called setter…

    Comments Off on Different types of dependency injection(DI)
  • DI,  IOC,  spring,  Spring Basics,  Spring Interview Questions

    Inversion of Control (IOC) Vs Dependency Injection (DI)

    IOC and DI are one of the same thing in aspects of Spring frame work, Both are meant to be for same functionality. Dependency injection (DI) is a programming design pattern and architectural model, sometimes also referred to as inversion of control or IOC, although technically speaking, dependency injection specifically refers to an implementation of a particular form of IOC. Dependency Injection describes the situation where one object uses a second object to provide a particular capacity. For example, being passed a database connection as an argument to the constructor instead of creating one internally. The term “Dependency injection” is a misnomer, since it is not a dependency that is…

    Comments Off on Inversion of Control (IOC) Vs Dependency Injection (DI)