Spring Introduction
Spring Introduction
-----------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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
3)AutoConfiguration:
4)Embedded servers:
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.
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.
- 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 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 {
1) data source
2) smtp
3) actuators
4) kafka
5) redis etc..
-------------------------------------------------------------------------
-> In boot application by default test class also created
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>
-> 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{
@SpringBootApplication annotation
-------------------------------------------------------------------------
-> @SpringBootApplication annotation is used to represent start class.
-------------------------------------------------------------------------
@SpringBootApplication
public class Application{
@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.
-> 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
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");
}