SpringBoot:
- SpringBoot is an open source Java based framework used to create a Microservice.
- It is easy to create a standalone and production-ready Spring applications using SpringBoot.
- SpringBoot contains complete infrastructure support for developing a Microservice and develop enterprise ready application which can be "just run".
Microservice ?
- Microservice is an architecture that allows developer to develop and deploy services independently.
- Each running service has its own process and this achieves the light-weight model to support business applications.
Microservice Advantages:
- Easy deployment
- Simple scalability
- Compatible with containers
- Minimum configuration
- Less production time
SpringBoot Advantages:
- Includes embedded Servlet container
- Easy dependency management
- Provides annotation based Spring application
- Provides flexible way to configure Java Beans, XML configurations and DB Transactions
- Provides powerful Batch-processing and manages REST endpoints
Goals:
- Avoid complex XML configurations in Spring
- Develop a production-ready Spring applications in easy way
- Reduce development time and run application independently
- Provide easy way of getting started with the application
SpringBoot working:
- SpringBoot automatically configures your application based upon dependencies, that are added in the project by using @EnableAutoConfiguration annotation.
e.g. If MySQL database is on classpath, but you have not configured any DB connection, then SpringBoot auto-configures an in-memory DB. - The entry point of SpringBoot application is the class that contains @SpringBootApplication annotation and main() method.
- SpringBoot automatically scans all components included in project using @ComponentScan annotation.
SpringBoot Starters :
- SpringBoot resolves dependency management by providing a set of dependencies for developer convenience.
- SpringBoot Starter Data JPA dependency:
If you need Spring and JPA for DB access, you only include spring-boot-starter-data-jpa dependency in project.<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
- SpringBoot Starter Web dependency:
Used to write REST endpoints.<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
- SpringBoot Starter Thyme Leaf dependency:
Used to create a Web-application.<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
- SpringBoot Starter Test dependency: Used for writing Testcases.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>
AutoConfiguration:
- SpringBoot Auto Configuration automatically configures the Spring application based on the JAR dependencies added in project.
e.g. If MySQL database is on classpath, but you have not configured any DB connection, then SpringBoot auto-configures an in-memory DB. - To automatically enable SpringBoot Apllication, add @EnableAutoConfiguration or @SpringBootAppplication to main class file.
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @EnableAutoConfiguration public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
ComponentScan:
- SpringBoot Application scans all beans and package declarations when the application initializes.
- After adding @ComponentScan, main class file scans your components added in project.
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @ComponentScan
public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
SpringBoot Application:
- Entry point of SpringBoot Application is class that contains @SpringBootApplication.
- This class should have main() to run the SpringBoot Application.
- It includes :
- @AutoConfiguration
- @ComponentScan
- @SpringBootConfiguration
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
a
No comments:
Post a Comment