Alphalearningschool
        

<<< Prev

Up
Spring Boot Interview Questions

Q1. What is Spring Boot? And why it is used?

Ans. Spring boot is a framework which is designed by the Spring team which facilitates in creating the applications in much easier way. This provide spring module which has RAD (Rapid Application Development) feature. In other words, we can that spring boot is the extended version of the Spring framework which helps to solve all the previous problems faced by spring community.

 >> Advantages of using this Spring Boot:

  • 1.Quite easy to work with JAVA codes in creating spring based applications.
  • 2.Spring Development is made simplified because of Spring Boot.
  • 3.Compactable with in co ordination with Spring Boot Application with its Spring Eco system like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
  • 4.Lot of plug-in options is there to work in Spring boot in creating applications.
  • 5.Using build tools like Maven and Gradle, spring based applications can be easily created and tested effectively.

Q2. What is the difference between Spring and Spring Boot?

Ans. Spring is a framework helps in creating web applications. It provides tools and libraries which helps in creating a complete web application and it can be customized anytime.

Spring boot is a spring module which will create spring application that can just run.

Q3. How to create Spring Boot application using Maven?

Ans. Using Maven, we can create Spring Boot application:

  • >>Spring starter project wizard
  • >>Spring Initializr
  • >>Spring Maven project
  • >>Spring Boot CLI

Q4. What do you mean by spring boot starters?

Ans. Spring boot starters are nothing but a set of convenient dependency descriptors which can be included in applications.

Spring boot facilitate build-in starter which helps us in creating application much easier and faster.

Example of spring boot starters:

  • 1. The Web Starter
  • 2. The Test Starter
  • 3. The Data JPA Starter
  • 4. The Mail Starter

Q5. What is spring boot actuator?

Ans. Actuator is basically helps in managing and monitoring the applications. They provide “Management Endpoints” to see Application Internals, Metrics etc.

To enable Spring boot Actuator, Actuator dependency is added in POM file:

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

 

Q6. What is the difference between RequestMapping and GetMapping?

Ans. RequestMapping is generic in nature- Multiple request methods like GET, POST, PUT etc can be used easily using the method attribute on the annotation.

GetMapping is specified to only one functionality only that is Get request method. It’s just an extension of RequestMapping to improve clarity.

Q7. What is the way to reload changes on Spring boot without server-restart?

Ans. Any changes are reloaded in spring boot without starting the server by using dev tools.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

 

Q8. How to run Spring boot application to custom port?

Ans. We need to specify the port in application.properties in order to run a spring boot application.

         server.port=8080

         This entry will ensure that application would run on 8080 port.

 Q9. Is it possible to write Test cases using Spring Boot?

Ans. Yes, it’s possible. Spring boot provides the @SpringBootTest annotation for writing Unit Test Cases.

Q10. What is the way to configure logging in Spring boot application?

Ans. Logging level can be easily specified in the application.properties files:

        Logging.level.spring.framework=Debug

The above line present in application properties file will help us log to the debug level.

If a developer wants to put logs in the file, then the developer can specify logger file in application properties.

Logging.file= ${java.io.tempdirectory}/samplelog

Apart from the above approaches, a developer can make a logback.xml file under main/java/resources and can specify the logging configuration in the file. Spring boot will automatically detect this file easily.

Q11. What is the way to implement Spring batch in spring boot?

Ans. Processing a batch involves processing large amount of data. Spring boot batch provides a function which is reusable and important for batch processing. It gives services and features which can be optimized and helps in partition techniques which results to give high performance batch jobs.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<optional>true</optional>
</dependency>

Any changes done in POM file will include necessary packages in application, which are required to process the batch in spring boot project.

Q12. What is the way to add custom JS code in Spring boot application?

Ans. A folder is created by the name “static” under the resources folder. Then all the static contents can be put into this folder.

Test.js is the javascript file would reside in /resources/static/js/test.js

The file can be referred in JSP like: <script src =”/js/test.js”></script>