Spring 1_Introduction and IOC
Spring 1_Introduction and IOC
Framework-
It is nothing but to provide the common things which is required for software
development called as framework.
1. Predefined template-
It provides templates for hibernate, JPA, JDBC, etc. there is no need
to write too much code.
Example- in JDBC template, you don’t need to write code for
exception handling, creating connection, creating statement, closing
connection. Only the thing is that you need to write the code for executing
the query only.
2. Loosing coupling-
Spring applications are loosely coupled because of dependency
injection.
3. Easy to test-
Spring does not require server to run the program. It only need JDK
and Jar file.
4. Light weight-
Spring is light weight component due to its POJO implementation. It
does not force any programmer to inherit the class or implement any
interface.
Example-
package com.test
public class A {
B b = new B ();
}
public class B{
package com.test
package com.test
Here class A is compatible with any class. In future, if you don’t want B
class then you can create the one more class named as class C and pass the object
as below. Demo i= new C (); // i is the interface reference.
Class A {
Class B {
B b=new B ();
Again, In future, I want to create the object of Class C then what will happen here?
C c=new C ();
So here we are giving control to spring that you have to create the object on the
behalf of me. Means no need to worry about object creation.
Why container?
If you want to pass / apply any input to pojo classes. You must have container
supports.
BeanFactory-
1. Calculator
3. Antivirus
2. onlinesbi
Fig- BeanFactory
Note-