You are on page 1of 7

Spring :

Spring is an application development framework.

By using spring framework we can develop end to end application.

By using spring framework we can develop below applications.

1)Standalone application Ex: notepad,calculator.


2)Web application(Customer to business) :Ex: facebook,irctc,redbus ,enam etc.
3)Distributed application(business to business)

spring framework is develped in modular fashion.


1)spring core
2)spring web mvc
3)Spring orm(Object relational mapping)
4)Spring aop(Aspected oriented programming)
5)Spring context

Note:spring core is base module for other modules in spring framework.

spring core module provides fundamental concepts i.e


1)IOC
2)Dependency injection

spring is versatile framework.(spring can integrate with other frameworks easily).

spring is non-invasive framework.(spring doesnt force to implement class and


interfaces of spring)

spring framework provides loosely coupling among the classes in application.

-----------------------------------------------------------------------------
Disadvantages of spring framework ?
Spring framework provides lot of things for us but we have to intregrate all those
things by writting lot of configurations.

Programmer is responsible to take care of configurations manually in spring


framework.

--------------------------------------------------------------------------------

SpringBoot: Springboot is an apporach to develop spring based applications with


less
or minimal configurations

Springboot came into market to provide Auto_configuratins for application


development.

SpringBoot internallty uses springframework.

Note:SpringBoot is not replacement for Spring framework.Springboot is only


promoting spring framework.

Advantages:

1)Starter poms:
SpringBoot provides Starter POMS.

1)spring-boot-starter-web
2)spring-boot-starter-data-jpa
3)spring-boot-starter-mail
4)spring-boot-starter-security
5)spring-boot-starter-actuator
6)spring-boot-starter-webflux

2)Version management

Springboot provides version management.For dependencies we no need to write version


number.springboot
will take care of that.

3)AutoConfiguration:

It provide Auto_configuratins for application development.Springboot is responsible


to do
configurations automatically.

4)Embedded servers:

Springboot provides embedded servers to run our web applications.Tomcat is the


default embedded
server provided by SpringBoot.

5)Actuators
Springboot provides Actuators.
Actuators are mainly used to provide production ready features.

1)class loaded
2)thread running(thread dump)
3)objects created(heap dump)
4)health
5)info
6)environment.

We can create sping boot application in 2 ways

a) Spring Initiazr website (start.spring.io)

b) Using IDE (Eclipse/STS/Intelli J)

Spring Initializer:
-> Spring Intializr is used to create spring boot applications

start.spring.io

-> When we create boot application using initializr it will give the application in
the form of zip file.

-> We need to extract that zip file and we should import that project into our IDE.

-> We can create spring boot application directley from IDE but internally IDE will
interact with start.spring.io website to create the project.

Note: We should have internet connection to create spring boot applications.

Spring Boot application folder structure


----------------------------------------

- 01-SpringBoot-App
- src/main/java
- com.bikkadit
- Application.java
- src/main/resources
- application.properties
- src/test/java
- com.bikkadit
- ApplicationTest.java
- Maven Dependencies
- jar files
- pom.xml

Spring Boot application folder structure


-------------------------------------------------------------------------
-> Spring Boot application we have created using Maven build tool

src/main/java -------------> application source code here

src/main/resources --------> .xml, .yml, .props here

src/test/java -------------> unit test classes here

Maven Dependencies --------> Dependencies will display here

target -------------------> .class files & artifacts

pom.xml ------------------> Maven config file

-> When we create boot application we are getting "Application.java" class by


default.
This class is called as start class of Spring Boot.

-> Spring Boot start class is also called as Main class in boot application.

-> Spring Boot application execution will begin from main class only.

------------------------------Application.java---------------------------
@SpringBootApplication
public class Application {

public static void main(String... args){


SpringApplication.run(Application.class, args);
}
}
-------------------------------------------------------------------------
-> application.properties file will be created under src/main/resource folder.

-> In this properties we will configure application config props like

1) data source
2) smtp
3) actuators
4) kafka
5) redis etc..

Note: Instead of properties file we can use .yml file also.

-> YAML/YML stands for Yet Another Markup Language

-------------------------------------------------------------------------
-> In boot application by default test class also created

@SpringBootTest ----> To represent class as SB test class

@Test ------> To represent one method as test case

A-------------------------------ApplicationTest.java----------------------
@SpringBootTest
class ApplicationTests {

@Test
void contextLoads() {
}
}
-------------------------------------------------------------------------
-> In Boot application by default we will get below 2 dependencies

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Bootstrapping process in Spring Boot


---------------------------------------------------------------------
-> When we create Spring boot starter project by default we will get Boot start
class.
It is also called as main class in boot application.

-> Spring Boot application execution will begin from that start class only.

-> That boot start class contains main method which calls SpringApplication.run(..)
method

------------------------------------------------------------------------
@SpringBootApplication
public class Application{

public static void main(String... args){


SpringApplication.run(Application.class, args);
}
}

@SpringBootApplication annotation
-------------------------------------------------------------------------
-> @SpringBootApplication annotation is used to represent start class.
-------------------------------------------------------------------------
@SpringBootApplication
public class Application{

public static void main(String[] args){


SpringApplication.run(Application.class, args);
}
}
-------------------------------------------------------------------------
-> @SpringBootApplication annotation is equal to below 3 annotations

@ComponentScan
@SpringBootConfiguration
@EnableAutoConfiguration

-------------------------------------------------------------------------
@ComponentScan
-------------------------------------------------------------------------
-> Component Scan is the process of identifying java classes which are represented
as Spring Beans.

-> In Spring Boot, Component Scan is enabled by default. When we run our boot
application "Component Scan" will happen by default.

-> Component Scan will follow package naming convention to scan for the java
classes which are represented as spring beans.

-> Component Scan always will start from base package.

-> The package which contains boot start class is called as base pckg.

-> After base package scanning got completed, it will start scanning of sub
packages of base package.

-> The package names which are starting with base package name are called as sub-
packages of base package.
com.bikkadIt(base pkg)
com.bikkadIt.service --------- will be scanned
com.bikkadIt.dao ------------- will be scanned
com.bikkadIt.util ------------ will be scanned
in.bikkadIt.controller ----- will not be scanned

@SpringbootConfiguration Annotation :It is equal to @Configuration annotation.


It represents our class as configuration class.

@EnableAutoConfiguration Annotation :it identifies the configuration which is


required to run our
application and will provide that configurations automatically.

Example :

package com.BikkadIT.FirstProjectUsingIde;

import org.springframework.stereotype.Component;

@Component
public class Demo {

public Demo() {
super();
System.out.println("Demo Class Constructor");
}

package com.BikkadIT.FirstProjectUsingIde;

import org.springframework.stereotype.Component;

@Component
public class Demo1 {

public Demo1() {
super();
System.out.println("Demo1 class Constructor");
}

package com.BikkadIT.FirstProjectUsingIde.controller;

import org.springframework.stereotype.Component;

@Component
public class WelcomeController {

public WelcomeController() {
super();
System.out.println("Welcome class Constructor");
}

}
package com.BikkadIT.FirstProjectUsingIde.model;

import org.springframework.stereotype.Component;

@Component
public class Student {

public Student() {
super();
System.out.println("Student class Constructor");
}

package in.BikkadIT.FirstProjectUsingIde;

import org.springframework.stereotype.Component;

@Component
public class Employee {

public Employee() {
super();
System.out.println("Employee Class Constructor");
}

You might also like