Posts

IoC and DI in Spring

IoC(Inversion of Control): Normally, in Java, we create references/variables by declaring them and then assigning a value to them or if reference by creating an object by calling its constructor with new. In this process, the total control of instantiating, configuring the variables/references(or)beans is with the developer. Instead, if this given to some other component, the task of providing the developer with objects meaning the task of creating objects is taken away from developer(can do if wishes to, but, won't be IoC), the normal process is inverted, hence called 'Inversion of Control'. Now, in Spring, this is done by IoC Container- ApplicationContext . The Spring Container is responsible for instantiating, configuring and managing lifecycle of beans. Spring framework provides several implementations of ApplicationContext- ClassPathXmlApplicationContext, FileSystemXmlApplicationContext and WebApplicationContext(for web applications). DI (De

Creation of Spring + Hibernate + Maven Application

Image
1. Create a Maven Project in eclipse. 2.In the pom.xml, add the dependencies for Spring artifacts( spring-context,   commons-logging ,  spring-core ), for Hibernate artifacts( hibernate-core ) and your database specific connector, for example for mysql( mysql-connector-java ). For all these artifacts, search on maven repository and copy the required version dependency and place them inside <dependencies> tag of pom.xml. 3. Create  a POJO Employee(a simple java class and name it Employee.java), define the properties in the class and provide getter and setter methods for the properties of Employee class. Employee.java public class Employee {         private  String  name ;         private int  id ;         public  String getName() {                return  name ;         }         public   void  setName(String  name ) {                this . name  =  name ;         }         public   int  getId() {                return  id ;