0% found this document useful (0 votes)
34 views5 pages

Interview SpringBoot

Spring Boot is a framework that provides rapid application development features to Spring. It allows creating standalone Spring applications that can be started using a jar file. Spring Boot provides auto-configuration and starter POMs to simplify configuration. It automatically configures Spring whenever possible. Common annotations in Spring Boot include @Component, @Controller, @Service, @Repository, and @Autowired for dependency injection. The Spring Boot actuator allows monitoring and managing applications by exposing HTTP endpoints. Aspect-oriented programming (AOP) with Spring Boot handles cross-cutting concerns.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
34 views5 pages

Interview SpringBoot

Spring Boot is a framework that provides rapid application development features to Spring. It allows creating standalone Spring applications that can be started using a jar file. Spring Boot provides auto-configuration and starter POMs to simplify configuration. It automatically configures Spring whenever possible. Common annotations in Spring Boot include @Component, @Controller, @Service, @Repository, and @Autowired for dependency injection. The Spring Boot actuator allows monitoring and managing applications by exposing HTTP endpoints. Aspect-oriented programming (AOP) with Spring Boot handles cross-cutting concerns.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Interview Question

1. Spring Boot
1.1 What is Spring Boot?

Spring Boot is a Spring module which provides RAD (Rapid Application Development) feature to
Spring framework.

It is used to create standalone spring based application that you can just run because it needs very
little spring configuration.

Spring boot is used to develop the REST API.

Advantage

o Create stand-alone Spring applications that can be started using java -jar.
o Embed Tomcat, Jetty or Undertow directly. You don't need to deploy WAR files.
o It provides opinionated 'starter' POMs to simplify your Maven configuration.
o It automatically configure Spring whenever possible.

1.2 Spring boot Feature


 Web Development
 SpringApplication
 Application events and listeners
 Admin features

1.3 @SpringbootApplication
@SpringBootApplication=@ComponentScan+@EnableAutoConfiguration+@Configuration

1.3 Spring Boot Annotations


Spring Boot Annotations is a form of metadata that provides data about a program. In other words,
annotations are used to provide supplemental information about a program. It is not a part of the
application that we develop. It does not have a direct effect on the operation of the code they annotate.
It does not change the action of the compiled program.

1.3.1@Required:
It applies to the bean setter method. It indicates that the annotated bean must be populated at
configuration time with the required property, else it throws an
exception BeanInitilizationException.
1.3.2 @Autowired:
Autowiring feature of spring framework enables you to inject the object dependency implicitly.
It internally uses setter or constructor injection.
1.3.3@Configuration:
It is a class-level annotation. The class annotated with @Configuration used by Spring Containers as a
source of bean definitions.
1.3.4 @Component:
It is a class-level annotation. It is used to mark a Java class as a bean. A Java class annotated
with @Component is found during the classpath. The Spring Framework pick it up and configure it
in the application context as a Spring Bean.

1.3.5 @Controller:
The @Controller is a class-level annotation. It is a specialization of @Component. It marks a class as
a web request handler. It is often used to serve web pages. By default, it returns a string that indicates
which route to redirect. It is mostly used with @RequestMapping annotation.

1.3.6 @Service:
It is also used at class level. It tells the Spring that class contains the business logic.
1.3.7 @Repository:
It is a class-level annotation. The repository is a DAOs (Data Access Object) that access the database
directly. The repository does all the operations related to the database.
1.3.7 @EnableAutoConfiguration:

The @EnableAutoConfiguration annotation enables Spring Boot's auto-configuration feature. This


feature automatically configures the application by scanning the classpath components and registering
the beans.

1.3.8 @SpringBootApplication:

It is a combination of three annotations @EnableAutoConfiguration,


@ComponentScan, and @Configuration.

1.3.9: @RequestMapping

It is used to map the web requests. It has many optional elements like consumes, header,
method, name, params, path, produces, and value. We use it with the class as well as the
method.

1.3.10 @RestController:
@RestController is an annotation in Spring Boot that simplifies the creation of RESTful web services.

It combines the @Controller and @ResponseBody annotations.

1.4 REST API Annotation


@GetMapping:

It maps the HTTP GET requests on the specific handler method. It is used to create a web
service endpoint that fetches It is used instead of using: @RequestMapping(method =
RequestMethod.GET)

@PostMapping:

It maps the HTTP POST requests on the specific handler method. It is used to create a web
service endpoint that creates It is used instead of using: @RequestMapping(method =
RequestMethod.POST)

@PutMapping:

It maps the HTTP PUT requests on the specific handler method. It is used to create a web
service endpoint that creates or updates It is used instead of
using: @RequestMapping(method = RequestMethod.PUT)

@DeleteMapping:

It maps the HTTP DELETE requests on the specific handler method. It is used to create a
web service endpoint that deletes a resource. It is used instead of
using: @RequestMapping(method = RequestMethod.DELETE)

@PatchMapping:

It maps the HTTP PATCH requests on the specific handler method. It is used instead of
using: @RequestMapping(method = RequestMethod.PATCH)

@RequestBody:

It is used to bind HTTP request with an object in a method parameter. Internally it


uses HTTP MessageConverters to convert the body of the request. When we annotate a
method parameter with @RequestBody, the Spring framework binds the incoming HTTP
request body to that parameter.

@ResponseBody:

It binds the method return value to the response body. It tells the Spring Boot Framework to
serialize a return an object into JSON and XML format.

@PathVariable:

It is used to extract the values from the URI. It is most suitable for the RESTful web service,
where the URL contains a path variable. We can define multiple @PathVariable in a method.
@RequestParam:

It is used to extract the query parameters form the URL. It is also known as a query
parameter. It is most suitable for web applications. It can specify default values if the query
parameter is not present in the URL.

@RequestHeader:

It is used to get the details about the HTTP request headers. We use this annotation as
a method parameter. The optional elements of the annotation are name, required, value,
defaultValue. For each detail in the header, we should specify separate annotations. We can
use it multiple time in a method

@RestController:

It can be considered as a combination


of @Controller and @ResponseBody annotations. The @RestController annotation is itself
annotated with the @ResponseBody annotation. It eliminates the need for annotating each
method with @ResponseBody.

@RequestAttribute:

It binds a method parameter to request attribute. It provides convenient access to the request
attributes from a controller method. With the help of @RequestAttribute annotation, we can
access objects that are populated on the server-side.

1.5 What is Spring boot Actuator?


Spring Boot provides actuator to monitor and manage our application. Actuator is a tool which has
HTTP endpoints. when application is pushed to production, you can choose to manage and monitor
your application using HTTP endpoints.

1.6 Cross-cutting concerns


The responsibility of each layer is different, but there are a few common aspects that apply to all
layers are Logging, Security, validation, caching, etc. These common aspects are called cross-
cutting concerns.
If we implement these concerns in each layer separately, the code becomes more difficult to maintain.
To overcome this problem, Aspect-Oriented Programming (AOP) provides a solution to implement
cross-cutting concerns.

1.6 AOP (Aspect object Programming)


AOP (Aspect-Oriented Programming) is a programming pattern that increases modularity by
allowing the separation of the cross-cutting concern. These cross-cutting concerns are different from
the main business logic. We can add additional behaviour to existing code without modification of the
code itself.
For more check https://www.javatpoint.com/spring-boot-aop

1.7 Autowiring @Autowired


Autowiring feature of spring framework enables you to inject the object dependency implicitly.
It internally uses setter or constructor injection.

1.8. What is dependency Injection?

The process of injecting dependent bean objects into target bean objects is called
dependency injection.

 Setter Injection: The IOC container will inject the dependent bean object into the target bean
object by calling the setter method.
 Constructor Injection: The IOC container will inject the dependent bean object into the target
bean object by calling the target bean constructor.
 Field Injection: The IOC container will inject the dependent bean object into the target bean
object by Reflection API.

1.9. What is an IOC container?

IoC Container is a framework for implementing automatic dependency injection. It


manages object creation and its life-time and also injects dependencies into the class

1.10 what is beans


In Spring, the objects that form the backbone of your application and that are
managed by the Spring IoC container are called beans.

You might also like