SPRINGBOOT Flashcards

REVISION

1
Q

What is the Spring Boot ?

A

Spring Boot is an open-source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production-ready spring applications.
Spring Boot offers the following advantages to its developers −

Easy to understand and develop spring applications
Increases productivity
Reduces the development time
Goals
Spring Boot is designed with the following goals −

To avoid complex XML configuration in Spring
To develop a production ready Spring applications in an easier way
To reduce the development time and run the application independently
Offer an easier way of getting started with the application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Micro Service?

A

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

Advantages
Microservices offer the following advantages to its developers −

Easy deployment
Simple scalability
Compatible with Containers
Minimum configuration
Lesser production time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does it work?

A

Spring Boot automatically configures your application based on the dependencies you have added to the project by using @EnableAutoConfiguration annotation. For example, if MySQL database is on your classpath, but you have not configured any database connection, then Spring Boot auto-configures an in-memory database.

The entry point of the spring boot application is the class contains @SpringBootApplication annotation and the main method.

Spring Boot automatically scans all the components included in the project by using @ComponentScan annotation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Auto Configuration

A

Spring Boot Auto Configuration automatically configures your Spring application based on the JAR dependencies you added in the project. For example, if MySQL database is on your class path, but you have not configured any database connection, then Spring Boot auto-configures an in-memory database.

For this purpose, you need to add @EnableAutoConfiguration annotation or @SpringBootApplication annotation to your main class file. Then, your Spring Boot application will be automatically configured.

Observe the following code for a better understanding −

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);
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Spring Boot Application

A

The entry point of the Spring Boot Application is the class contains @SpringBootApplication annotation. This class should have the main method to run the Spring Boot application. @SpringBootApplication annotation includes Auto- Configuration, Component Scan, and Spring Boot Configuration.

If you added @SpringBootApplication annotation to the class, you do not need to add the @EnableAutoConfiguration, @ComponentScan, and @SpringBootConfiguration annotation. The @SpringBootApplication annotation includes all other annotations.

Observe the following code for a better understanding −

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

@SpringBootApplication
public class DemoApplication {
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain Entry point in Springboot Application ?

A

The main method should be writing the Spring Boot Application class. This class should be annotated with @SpringBootApplication. This is the entry point of the spring boot application to start. You can find the main class file under src/java/main directories with the default package.

In this example, the main class file is located at the src/java/main directories with the default package com.tutorialspoint.demo. Observe the code shown here for a better understanding −

package com.tutorialspoint.demo;

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

@SpringBootApplication
public class DemoApplication {
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Spring Boot - Tomcat Deployment ?

A

We need to extend the class SpringBootServletInitializer to support WAR file deployment.

@SpringBootApplication
public class DemoApplication  extends SpringBootServletInitializer {
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(DemoApplication.class);
   }
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
}
2)
add the start class in pom.xml properties as shown below −

com.tutorialspoint.demo.DemoApplication

3)
add the packaging as WAR in pom.xml as shown below −

war

How well did you know this?
1
Not at all
2
3
4
5
Perfectly