00 Intro
Spring Boot is an open-source Java-based framework for creating standalone, production-grade Spring-based Applications. It is a project built on the top of the Spring Framework, which simplifies the development of new Spring applications. It is a pre-configured way of developing Spring applications.
History
Spring Boot was developed by Pivotal Software and released in 2014. It was created to simplify the development of new Spring applications. It provides a pre-configured way of developing Spring applications.
Instead of using J2EE with EJB (Enterprise JavaBeans), Spring Boot uses POJOs (Plain Old Java Objects) and annotations. It simplifies the development process by providing default configuration and settings.
Concepts
- Convention over Configuration: Spring Boot is a convention-over-configuration framework. It means that it reduces the developer effort by providing default configuration and settings. It allows the developer to focus on the business logic of the application.
- Plain Old Java Object (POJO): Spring Boot uses POJOs to develop applications. It simplifies the development process by removing the need for EJBs (Enterprise JavaBeans).
- Aspect-Oriented Programming (AOP): Spring Boot uses AOP to separate cross-cutting concerns from the business logic of the application. It allows the developer to focus on the business logic of the application.
- Dependency Injection (DI): Spring Boot uses DI to inject dependencies into the application. It allows the developer to decouple the dependencies from the application logic.
- Inversion of Control (IoC): Spring Boot uses IoC to manage the dependencies of the application. It allows the developer to focus on the business logic of the application.
- Containerless: Spring Boot runs on an embedded server, which means that it does not require a separate application server to run the application.
First Spring Application
Create a new Spring project and replace the content of the Application.java file with the following code:
@SpringBootApplication
@RestController
public class SpringIocApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SpringIocApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Hello World");
}
@GetMapping("/hello")
public String hello(@RequestParam(defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}