Getting Started with Spring Boot

07 / Nov / 2022 by Moin Malik 0 comments

What is Spring Boot?

Spring Boot is now an open-source Java-Based framework to create standalone microservices with production-ready features. It is heavily maintained by the Pivotal team. Microservices is an architectural design that creates scalable, loosely coupled, and testable applications with a single function module with a well-defined interface.

What is MicroService?

MicroService is an architecture that allows developers to develop and deploy services independently. Each service running has its own process, and this achieves the lightweight model to support business applications.

Build tools — Maven and Gradle

How does it work? @SpringBootApplication

Spring Boot starters

Examples

Its code is shown below −

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

Its code is shown below −

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

Its code is shown below −

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

Its code is shown below −

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

Its code is shown below −

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

Auto Configuration

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

@EnableAutoConfigurationpublic 
class DemoApplication {
          public static void main(String[] args) {
                 SpringApplication.run(DemoApplication.class, args);
               }
}

Spring Boot Application

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplicationpublic 
class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

Core Spring framework annotations

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
class DemoApplication {
@Bean
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}}
}
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;@ComponentScanpublic 
class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

Component Scan

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;@ComponentScanpublic 
class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *