SpringBootQuestions Flashcards

1
Q

What is Spring?

A

Spring is a powerful, open-source, lightweight, loose coupled, framework meant to reduce the complexity of developing applications.

Spring handles all the structure-related aspects which allow the developer to focus mostly on application development.

Some of the features of Spring are:

  • Inversion of Control:
  • Creating and Managing: the lifecycle of the applications objects
  • Highly Configurable: Allows switching frameworks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Spring Boot?

A

Spring Boot is an open-source, java-based framework that provides an easier and faster way to set up, configure and run production-ready Spring applications with a need for very few configurations.

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

Spring vs Spring Boot

A

The difference between Spring and Spring Boot is

  • Spring, is a widely used Java framework that helps develop loosely coupled applications.
  • The most commonly used features of the Spring framework are Dependency Injection, however, it does offer many other features, like the container, which creates and manages the lifecycle of the beans, meaning the objects and many others.
  • With Spring, the developer has to manually define dependencies for the project in the pom file.

The Sprint Boot Framework:

  • internally takes care of downloading the dependencies JARs based on Spring Boot Requirements,
  • which helps to create applications with less configuration.
  • Spring Boot’s primary feature is auto-configuration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Mentioned some features of Spring Boot

A
Auto-Configuration - 
Starter Dependency - 
Spring Initializer - Easily builds the structure of the project
Spring Actuator - 
Logging & Security
Spring CLI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Spring Boot

Describe the feature Starter Dependency

A

Starter Dependency – With the help of this feature, Spring Boot bundles common dependencies together and eventually improves productivity and reduces the burden on having to look through code to find the dependencies needed for the project.

Some of the most used starter dependencies are;

  • spring-boot-starter-parent
  • spring-boot-starter-web
  • spring-boot-starter-test
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Spring Boot

Describe the Spring Initializer feature

A

The Spring Initializer helps the developer to easily create the internal project structure so that the developer doesn’t have to manually set up the structure of the project.

With this feature, the developer can add mostly used dependencies, such as Spring Web, Thymeleaf, and Spring Boot DevTools.

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

SpringBoot

Describe the feature of Auto-Configuration

A

The Auto-configuration automatically configures the Spring application based on the jar dependencies that the developer added to the pom file.

For example, if the H2 database Jar is present in the classpath and we have not configured any beans related to the database manually, the Spring Boot’s auto-configuration feature automatically configures it in the project.

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

What is the @SpringBootApplication annotation?

A

The @SpringBootApplication annotation is used in the main class and is a combination of the

@Configuration
@ComponentScan
and
@EnableAutoConfiguration

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

What is the @EnableAutoConfiguration annotation?

A

The @EnableAutoConfiguration annotation auto-configures the beans that are present in the classpath and scans for components.

It’s a combination of the:

@Configuration
@ComponentScan

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

What do you mean by IoC (Inversion of Control) Container?

A

Inversion of Control transfers the control of an object to a container.

Some of the advantages are:

  • Decoupling the execution of a task from the implementation
  • Making it easier to test a program by mocking its dependencies

Spring container is the most important part of the Spring Framework.

The Spring container uses Dependency Injection (DI) for managing the application components by creating objects known as beans, configuring them, and managing their life cycles.

The instructions for the spring container to do the tasks can be provided either by Java annotations, or Java code.

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

What are the Spring Boot starters?

A

Spring Boot starters are dependency management providers that can be included in the application pom file.

These starters, make development easier and avoids developers having to go through sample code for commonly used dependencies.

A couple of Spring Boot starters are:

  • spring-boot-starter-parent: Provides Java version, dependency, and plugin management for applications built with Maven
  • spring-boot-starter-web: Starter for building web applications, including RESTful applications using Spring MVC. Uses Tomcat as the embedded server.
  • spring-boot-starter-test - It’s used to test Spring Boot applications with libraries, including, JUnit, and Mockito
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between @Controller and @RestController?

A

The @Controller is a specialization annotation of the Component class.

The @RestController is a special version of the @Controller. It combines @Controller and @ResponseBody and simplifies the controller implementation.

Therefore, the @ResponseBody is not required.

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

How does the @ResponseBody annotation works

A

The @Response annotation enables serialization of the object into the HttpResponse

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

Why should we use Spring Booth?

A

We should use Spring Boot because:

  • Because the dependency injection approach is used in Java
  • It simplifies the integration of other Java frameworks like JPA
  • It reduces the cost and development time of the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Advantages of Spring Boot

A
  • Creates stand-alone Spring applications
  • It provides starter dependencies
  • Provides production-ready features such as metrics, and health check
  • Reduces having to write boilerplate code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Spring Boot limitations

A

The only one I know is that it can use dependencies that are not going to be used in the application. These dependencies increase the size of the application.

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

Can you describe in very simple steps the process of how the application works?

A
  • The client makes the HTTP requests (PUT or GET)
  • The request goes to the controller, and the controller maps that request and handles it. After that, it calls the service logic if required.
  • In the service layer, all the business logic is performed. It performs the logic on the data that is mapped to JPA with model classes.
  • The information is returned to the user if no error occurred.
18
Q

What is the @RequestMapping annotation?

A

The @RequestMapping annotation is one of the most commonly used annotations in Spring Boot.

It is considered a class-level annotation, however, the benefit of this annotation is that it can be applied to the controller class as well as methods.

The @RequestMapping annotation is the base path of the request into the controller, and the developer can apply additional method-level annotations to make mappings more specific to handler methods.

19
Q

What are Spring Annotations?

A

Spring annotation is a form of metadata that provides data about a program.

20
Q

Describe the @Required annotation

A

The @Required is a method-level annotation to the setter method of a bean property and making the setter-injection mandatory.

This annotation indicates that the required bean property must be injected with a value at the configuration time.

public class Company {

private Integer cid;
private String cname;
    @Required.    ******************
    public void setCid(Integer cid) {
        this.cid = cid;
    }
    public Integer getCid() {
        return cid;
    }
..... }
21
Q

Describe the @Autowired annotation

A

It is used to autowire spring beans on setters, instance variables, and constructors.
The spring container auto-wires the bean by matching the data type.

22
Q

What are the 5 Core Spring Framework annotations?

A
@Autowired
@Configuration 
@ComponentScan
@Bean 
@Required
23
Q

What are the 4 Spring Framework Stereotype annotations?

A

@Component - Advising Spring to manage the bean
@Controller - Receives HTTP requests
@Service - Business logic
@Repository - Data storing

24
Q

What are the 2 Spring Boot Annotations?

A

@SpringBootApplication

@EnableAutoConfiguration

25
Q

What are the 13 Spring MVC and REST Annotations?

A

@RequestMapping *

@GetMapping

@PostMapping

@PutMapping

@PatchMapping

@DeleteMapping

@RequestBody - Maps the HttpRequest body to object. Enables automatic deserialization of the body to Java object

@ResponseBody - Serializes the object into JSON or XML

@PathVariable - Takes variable value from the URI, adds it to the argument

@RequestParam

@RequestHeader

@RestContoller

@RequestAttribute

26
Q

Explain the @Qualifier annotation

A

The @Qualifier annotation tells Spring Boot which bean to use if there’s more than one bean in the container with the same type.

27
Q

What is Spring Boot dependency management?

A

Spring Boot Dependency Management is used to manage dependencies and configuration automatically without having to specify the version for any of the dependencies.

Spring Boot upgrades all dependencies automatically when the Sprint Boot version is updated.

28
Q

What are the Spring Boot properties?

A

Spring Boot provides properties that can be specified inside the project’s application.properties file.
These properties have default values, however, we can configure the properties to the project’s needs.

Example are:

  • Configure the application’s name
  • To change the port-id
  • This allows us to run the application in different environments
29
Q

Explain the Spring Actuator and its advantages

A

Spring Actuator is a feature that helps to monitor the application with metrics. Shows the status of the application.

30
Q

What is Dependency Injection?

A

The main idea of Dependency Injection is that the developer doesn’t have to create the objects, but has to describe how they should be created.

The components and services should not be connected in the code directly.

Describe how which services are needed by which components in the configuration file.

IoC container will take care of wiring them up together.

31
Q

What is Constructor-Based Dependency Injection?

A

Constructor-based Dependency Injection is when the container will invoke a constructor with arguments each representing a dependency we want to set.

32
Q

Define the 5 Springs Core Annotations

@Autowired
@Configuration 
@ComponentScan
@Bean 
@Required
A

@Autowired - I want Spring to create an object/bean and auto-wire it in this class. we can use autowiring on properties, setters, and constructors.

@Configuration - class is defining beans

@ComponentScan

@Bean - add to method to create a bean

@Required -

33
Q

Does the @ComponentScan annotation scan for beans in all the projects or only in the package?

A

The @ComponentScan annotation only scans for components in the package.

34
Q

ResponseBody vs ResponseEntity

A

The ResponseEntity is an HTTP response, includes:

headers
body
status

While @ResponseBody puts the return value into the body of the response, ResponseEntity also allows us to add headers and status codes.

35
Q

Micro.

Advantages of Microservices

A
  • Independent Development:
  • Independent Deployment:
  • Fault Isolation: Event if one service does not work properly, the system still continues to function.
  • Mixed Technology Stack: Different languages and different technologies can be used to build different services of the same application.
  • Individual Scaling: Individual components can scale per needed, instead of scaling the whole system.
36
Q

What do you know about Microservices architecture?

A

It’s a collection of small applications that together create a whole system.

Each application or microservice is independent of the other. If one of the applications is not working properly, the system

37
Q

What are the features of Microservices?

A

Decoupling: Services within the system are decoupled. The application as a whole can be easily built, and scale.

Continues Delivery: Allows frequent releases of software.

Independent: Developer and teams can work independently of each other, and increases speed

Different Technologies: Each service can have its own technology. Developers have the freedom to choose the best useful pattern to solve the business logic.

38
Q

Micro

Best Practices

A
  • Separate data store for each microservice
  • Separate build for Each Microservice
  • Deploy into Containers

-

39
Q

Micro
How does Microservices worl? what are their components?

Client > sends request to > Gateway / Load Balancer >

A

The GATEWAY > redirect the request to the appropriate service > SERVICE 1 OR SERVICE 2 > will use SERVICE DISCOVERY (EUREKA) to find route of communication between microservices

40
Q

Cons of microservices?

A
  • Increases troubleshooting challenges
  • Increases delay due to remote calls using REST
  • Difficult to maintain transactions safely
  • Costly: Needs independent databases
41
Q

Monolithic vs Microservice Architecture?

A

Monolith : Single unit: Big container tightly packaged

Microservice: a lot of units: Decoupled

42
Q

Challenges faced with Microservices?

A

A lot of components: Needs to manage BUILD, DEPLOY AND MONITOR of a lot more of components.

Maintain Configuration: Increased maintaining configuration across all the components