SPRINGBOOT FRAMEWORK
It was Developed by Rod Johnson in 2003.
Spring Framework make easy to develop JavaEE application.
OOP(Object Oriented Programming) Best practice in.
It is a Lightweight Framework open-source framework.
Spring is a Dependency Injection Framework of Java, with the help of
which we can make loosely coupled application.
Tightly-coupled: If degree of dependency of the entities are more
then it is known as Tightly coupled application.
In tightly coupled we cannot change the module easily as we have
to change the entire code again and again if we want a new mode or
object, “So it is a bad practice”.
Eg:
//dependency object - no:1
class car {
public void start(){
[Link]("Travel with car to
Banglore..");
}
}
//dependency object - no:2
class bike{
public void start(){
[Link]("Travel with bike to
Banglore..");
}
}
public class Traveller {
// static car c = new car(); //hardcoding (or)
creating object to call that car class
//this time e doesn't want to go with car rather than
bike.
static bike b = new bike();
// so here what happen the traveller totally depend
upon the car and bike, bus, flight class to move forward.
and we have to hardcode it again and again
public static void main(String[] args) {
[Link]();
}
}
Loosely Coupled:
The degree of dependency of the entities are less then it is known
as Loosely – Coupled application
which is used in spring framework mostly.
Eg:
package TightLoose_Coupling;
/* Suppose there is a traveller ----> choice ---> banglore
* in first case it choose car as a choice to travel banglore
* in second case it choose bike as a choice to travel banglore
* in third case it choose Bus as a choice to travel banglore
* in fourth case it choose Flight as a choice to travel
banglore */
interface Vehicle{
public void start();
}
//dependency object - no:1
class car implements Vehicle{
public void start(){
[Link]("Travel with car to Banglore..");
}
}
//dependency object - no:2
class bike implements Vehicle{
public void start(){
[Link]("Travel with bike to Banglore..");
}
}
public class Traveller {
static Vehicle v; //loosely coded
//setter method for vehicle
public void setVehicle(Vehicle v){
this.v = v;
}
public static void main(String[] args) {
Traveller t = new Traveller();
[Link](new car()); //going with car
[Link]();
[Link](new bike()); //going with bike
[Link]();
}
}
Definitions:
1. POJO: plain old java Object
2. Java Beans: Simple objects with only getters and setters.
3. Spring Beans: POJOs configured in the application Context
4. DTO (Data Transfer Objects): Beans used to move state
between layer.
5. Inversion of Control :
IoC provides mechanism of dependency Injection.
Application Context wraps the bean Factory which serves the
beans at the runtime of application.
Spring Boot provides auto-configuration of the Application
Context
Why Spring Boot?
Supports rapid development
Removes boilerplate of application setup
Cloud Native support but also traditional
Key Aspects:
1. Embedded tomcat
2. Auto-configuration of application context
3. Automatic Servlet Mappings
4. Database support and Hibernate/JPA dialect
5. Automatic Controller Mappings(Spring MVC use)
Auto Configuration:
Default opinionated configuration.
Easy to override defaults
Configuration of presence.
Dependency Injection:
It is a design pattern that are used to remove the dependency from
the programming code.
It makes the loosely coupled and easy to test and maintain.
Let ‘s understand with the help of code:
Class Employee {
Address address;
Employee () {
Address = new Address (); //hardcoding
}
}
In this above case the Employee class is totally depends upon the
address (or) we can say it is tightly coupled.
In IOC Case,
Class Employee {
Address address;
Employee (Address address ){
[Link] = address;
}
}
IOC – Inversion of Control
Container maintains your class Dependencies.
Objects injected at runtime or startup time
An object accepts the dependencies for construction instead of
constructing them.
Spring IOC
Bean factory.
Application Context
References (They are not created in bean factory they are initialized).
Analysis of construction order.
Annotations
Native Support in java core.
Metadata for code
Often used compiler or runtime instructions.
Great leverage point for pointcuts.
Proxies
Beans in Bean Factory are proxied.
Annotations drives proxies
Annotations are easy extension points for your own abstracts too
Spring Boot Architecture
UI LAYER productController
Business/Services productService
Layer
productDao
Data Access Layer
DB