Spring Boot is an open-source Java Framework make it easy for develop stand-alone application and production ready that you can "just run". Created project with a few click and started project with minimum configurations.
Why Spring Boot?
As you know Spring Boot is still base on Spring Framework, but many junior developers always ask, why we choose Spring Boot?
I can give you one example real life, Are you planning to cook Tom Yum for your family in this evening? Imagine you mix your own ingredients, you might end up with awful flavor. Luckily, nowadays commercial made Tom Yum Soup Powder. You can easily cook it.
From above example, mixing your own ingredients the same as using Spring Framework. You need to know each core components well and the way to combine it. Otherwise you will end up with a mess. Spring Boot is like Tom Yum Soup Powder you only need to know basic usage, all core components already mixed for you.
Key Features & Benefit
- Create stand-alone applications.
- Increase development productivity.
- Embed webserver(Tomcat, Jetty, Undertow) inside application, say no to WAR file.
- Using Java annotation-based for configuration, rarely use XML configuration.
- Easy ship your applications into container platform.
- Provide opinionated 'starter' dependencies to simplify your build configuration.
- Everything auto configuration, in some case you still use manual configuration to override.
- Suitable for microservices applications, since it stand-alone and independence.
How magic happen?
@SpringBootApplication
public class Application {
public static void main (String[] args) {
SpringApplication.run(Application.class);
}
}
Auto configuration annotations
- @EnableAutoConfiguration, It will auto configure base your dependencies your add to into your project. For example, you add dependency spring-boot-starter-security on application startup, Spring Boot will generate in memory user for you.
- @ComponentScan, this annotation use for scan all bean base on define package. By default Spring Boot will scan beans in project package only. For example, we create Spring Boot project with package cyou.bannalycode, so @ComponentScan will scan all beans under package cyou.bannalycode. Incase of we have third party library from our team and its declare under difference package, so we need to define @ComponentScan as below:
@SpringBootApplication(scanBasePackages ={"cyou.bannalycode", "io.example"})
@ComponentScan(basePackages = {"cyou.bannalycode", "io.example"})
public class Application {
public static void main (String[] args) {
SpringApplication.run(Application.class);
}
}
Spring Boot Starters
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.12.RELEASE</version><!--depend on your spring boot version-->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>2.3.12.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.12.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.15.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.15.RELEASE</version>
<scope>compile</scope>
</dependency>
- spring-boot-starter-web
- spring-boot-starter-security
- spring-boot-starter-data-jpa
- spring-boot-starter-logging
- spring-boot-starter-amqp
0 Comments