Spring boot interview question for fresher/Spring Boot Interview Questions and Answers for Freshers & Experienced

What is LiveReload in Spring Boot?

LiveReload is a spring-boot-devtools module that includes LiveReload server to trigger a browser refresh when a resource is changed. LiveReload server extensions are available freeware for Firefox, Chrome, and Safari.

Explain how to register a custom auto-configuration.

In order to register an auto-configuration class, you have to mention the fully-qualified name under the @EnableAutoConfiguration key META-INF/spring. factories file. Also, if we build the with maven, then this file should be placed in the resources/META-INT directory.

How does path=”sample”, collectionResourceRel=”sample” work with Spring Data Rest?

@RepositoryRestResource(collectionResourceRel = "sample", path = "sample")
public interface SampleRepository extends
PagingAndSortingRepository<Sample, Long>


a) path – This section is used to mention the segment under which the resource is to be exported.
b) collectionResourceRel – This value is used to generate links to the collection resource.

In which layer, should the boundary of a transaction start?

The boundary of the transaction should start from the Service Layer since the logic for the business transaction is present in this layer itself.

What is YAML?

This is a configuration file and it’s human-readable. The YAML file is much structured and looks easy to understand the configuration, It contains hierarchical configuration data.

What is Spring Boot Starter in Spring Boot Framework?

This is just Spring Boot Starters JAR Files. It’s used for auto dependency resolution.

What things affect what Spring Boot sets up?

Spring Boot's magic depends upon multiple things e.g. annotations, application's classpath, environment, etc. Spring CLI can automatically add packages to Groovy's default package if they are present in the application classpath. Similarly, you can enable auto-configuration by using @SpringBootApplication or @EnableAutoConfiguration annotations.

What are some common Spring Boot annotations?

Some of the common Spring Boot annotations are @EnableAutoConfiguration, which enables auto-configuration and @SpringBootApplication which combines @Configuration, @ComponentScan, and @EnableAutoConfiguration into one to provide Java configuration, component scanning and enable Spring Boot's auto-configuration features. Both annotations are usually placed in the main class.

What is the difference between Core Spring and Spring Boot?

Again, they are two different frameworks but comes under the same umbrella of the Spring framework. Core Spring generally refers to Spring container which provides dependency injection and inversion of control, a key feature of Spring framework which promoted writing Java application in a different way 15 years back. While Spring Boot is now doing the same for the Spring framework, it is promoting a new way to use the Spring framework in the Java project.

What is Swagger2?

Swagger is used to describing the structure of APIs. Swagger 2 is an open-source service provided in Spring Boot that makes it easier for the machines to identify the structure of APIs such as RESTful Web services.

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

What is the difference between JPA and Hibernate?

While JPA and Hibernate both are completely different entities, they are interconnected in certain ways. JPA is an API that provides developers with specifications and guidelines for implementation. However, it is not implementation and will require a tool that can implement the specifications.
Consequently, Hibernate comes into picture, which is nothing but a tool that follows the guideline as well as compulsory and optional specifications defined by JPA and makes it functional.
Using Hibernate for JPA implementation also allows you to switch over other implementation tools easily, which is not possible if used Hibernate alone.

How does JPA Work?

JPA stands for Java Persistence API, which is used as an API that allows the developers to work with objects. When you deal with a relational database, you have to make use of SQL statements in order to retrieve information for certain queries. JPA eliminates the need of using SQL statements and allows the developers to deal with objects without SQL statement requisite. Developers can perform actions such as accessing, modifying, managing, and persisting information.
A JPA persistence provider can create a database schema by following the information provided in metadata. Here, JPA metadata has to be defined in the Java class. Metadata can also be defined using XML. JPA can handle both static and dynamic object-based queries.

Have you used ActiveMQ in Spring Boot application? Do you know how to configure external ActiveMQ?

Spring Boot comes with embedded ActiveMQ.We need to use "spring–boot–starter–activemq" dependency in pom.xml and it will take care of all defaults and will configure ActiveMQ in the project.

If you want to configure external ActiveMQ then you need to just put "spring.activemq.broker-url" in application.properties and provide the URL of external ActiveMQ.

What are embedded containers which are supported by Spring Boot?

Spring boot contains embedded Tomcat, Jetty and undertow servers.

What is the primary difference between Spring and Spring Boot?

Spring is a web application development framework based on Java. On the other hand Spring Boot is an extension of the spring framework which eliminated the boilerplate configuration required for setup a Spring application.

How can you access a value defined in the application? What is properties file in Spring Boot?

Use the @Value annotation to access the properties which is defined in the application - properties file.

@Value("${custom.value}")

private String customVal;

What is spring-boot-starter-parent?

It is a special starter which makes Gradle or Maven dependency-management easy by adding jars to your classpath.

How are properties defined? Where?

You can define properties in the application.properties file exists in the classpath.

Example: configure default DataSource bean

database.host=localhost

What is the name of the configuration file which you can use in Spring Boot?

The configuration file used in Spring Boot projects is called application.properties. It is an important file which allows you to override your default configurations.

What are the steps to deploy Spring Boot web applications as JAR and WAR files?

To deploy a Spring Boot web application, you just have to add the following plugin in the pom.xml file:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

By using the above plugin, you will get a JAR executing the package phase. This JAR will contain all the necessary libraries and dependencies required. It will also contain an embedded server. So, you can basically run the application like an ordinary JAR file.

Note: The packaging element in the pom.xml file must be set to jar to build a JAR file as below:

<packaging>jar</packaging>
Similarly, if you want to build a WAR file, then you will mention
<packaging>war</packaging>

Can you use Spring Boot with applications which are not using Spring?

No, it is not possible as Spring Boot is limited to Spring application only.

What Does It Mean That Spring Boot Supports Relaxed Binding?

Relaxed binding in Spring Boot is applicable to the type-safe binding of configuration properties.

With relaxed binding, the key of a property doesn't need to be an exact match of a property name. Such an environment property can be written in camelCase, kebab-case, snake_case, or in uppercase with words separated by underscores.

What Are Possible Sources of External Configuration?

Spring Boot provides support for external configuration, allowing us to run the same application in various environments. We can use properties files, YAML files, environment variables, system properties and command-line option arguments to specify configuration properties.

What is the process that you need to follow to run Spring Boot application on the custom port?

In order to run a Spring Boot application, you require to put server.port properties in application.properties. For example, server.port=8050

What is the need for Spring Boot DevTools?

Spring Boot Dev Tools are an elaborated set of tools and aims to make the process of developing an application easier. If the application runs in the production, then this module is automatically disabled, repackaging of archives are also excluded by default. So, the Spring Boot Developer Tools applies properties to the respective development environments. To include the DevTools, you just have to add the following dependency into the pom.xml file:

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

Explain what is thymeleaf and how to use thymeleaf?

Thymeleaf is a server-side Java template engine used for web applications. It aims to bring natural template for your web application and can integrate well with Spring Framework and HTML5 Java web applications. To use Thymeleaf, you need to add the following code in the pom.xml file:

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

What is @Autowired annotation and its usage?

Same as the @Required annotation, @Autowired annotation can be used to bind or autowire bean with the setter method. In other words, one can implicitly define object dependency. It provides developers with control regarding autowiring.

Explain different phases of RAD model.

This is a frequently asked job interview. Various phases of RAD mode are:

a) Business Modeling: Based on the flow of information and distribution between various business channels, the product is designed.
b) Data Modeling : The information collected from business modeling is refined into a set of data objects that are significant for the business.
c) Application Generation: Automated tools are used for the construction of the software, to convert process and data models into prototypes.

Explain Spring Actuator and its advantages.

Spring Actuator is a cool feature of Spring Boot with the help of which you can see what is happening inside a running application. So, whenever you want to debug your application, and need to analyze the logs you need to understand what is happening in the application right? In such a scenario, the Spring Actuator provides easy access to features such as identifying beans, CPU usage, etc. The Spring Actuator provides a very easy way to access the production-ready REST points and fetch all kinds of information from the web. These points are secured using Spring Security’s content negotiation strategy.

Difference between POST and PUT methods?

Basically, Put is used to replace all the target resources with the selected/requested payload. On the other hand, Post method is used to submit or send data to the specific server or resource such as file upload, information, or changing the current status.
An explicitly created object suggest use of the Put method while server-specified name shows the use of Post method.
Put allows you to Put objects more than a single time and also allows creation or updation of resources using the exact object or URL.
On the other hand, Post allows multiple requests at the same time to make changes to an object or URL.

What are the types of HTTP methods and Corresponding RestTemplate methods?

1) GET: Read operations
Use: To retrieve the list of customers and use sorting, pagination, and filtering to navigate big lists.
Status codes: 200 – (OK) valid request, 404 – (Not Found) Invalid request.
2) POST: Location header with link to /customers/{id} containing new ID
Use: To create the newrecord with new id.
Status codes: 201 (Created), 404 (Not Found), 409 (Conflict) if resource already exists.
3) PUT: To update/replace every resource in the entire collection.
Use: To update/replace data
Status codes: 405 (Method Not Allowed), 200 (OK), or 204 (No Content), 404 (Not Found), in case of ID invalid or not found.
4) PATCH: unless you want to modify the collection itself.
Use: To update/modify data
Status codes: 405 (Method Not Allowed), 200 (OK), or 204 (No Content), 404 (Not Found), in case of ID invalid or not found.
5) DELETE: To completely delete the collection – often not desirable
Use: To perform deletion
Status codes: 405 (Method Not Allowed), 200 (OK), or 204 (No Content), 404 (Not Found), in case of ID invalid or not found.

What is REST API?

Restful API is one of the favorite Spring Boot Interview Questions and Answers of recruiters to interrogate a fresher candidate.
REST API or RESTful API is used to transfer HTTP requests such as Get, Post, Put, and Delete. REST or Representational Transfer is a technology that imitates the communication style used for web services.

What is MediaType?

MediaType is used to specify the type of data that is to be produced or consumed by the controller. This narrows down and aids with mapping.

What is @pathVariable?

@PathVariable annotation is used to directly extract information from the URI.

What is @ResponseBody annotation?

The task of @ResponseBody annotations is to inform the controller that the returned object has been serialized into Json, the returned value will be bound to HttpResponse body.
Here, Spring HTTP message converters serialize the return value to the type specified in HTTP header.

What is @RequestBody annotation?

@RequestBody annotation is used to bind a method parameter to incoming HTTP requests with the mentioned URL in @RequestMapping annotation.
Here, HTTP message convertors are used to map HttpRequest body to a domain object, which consequently helps to automatically deserialize the body to a Java object based on header present in the request.

What is @Configuration and why is it needed?

@Configuration is a Spring annotation that is used to indicate @Bean method declaration by a class. It can be processed by Spring container in order to create service requests and bean definitions during runtime.
@Configuration is:
Required, only when the annotated class is defined in the @ComponentScan annotation but is not passed explicitly.
Not Required, if the annotated class is passed in the source parameters while calling SpringApplication.run().

What is Spring Boot Actuator?

Once the application is deployed, Spring Boot Actuator allows you to bring production-ready features to it. Features for monitoring application, traffic patterns, metrics, health, env, and other operation-related insights are provided by the Spring Boot Actuator. It makes use of HTTP endpoints to enable the interaction, which can be extended further in multiple ways same as other components of Spring Boot.

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

What is Spring Boot CLI?

CLI stands for the Command Line Interface. Spring Boot CLI, as the name suggests, is used to begin quickly with the development using the Spring framework. Often, developers have to spend a lot of time after writing boilerplate code, which is nothing but a few lines of code that has to be included time by time with a little bit of modification.
Groovy scripts provided by Spring Boot CLI makers sure that app developers can spend time after conventional coding parts and business logic. Such a set up makes sure Spring application is developed and deployed more quickly and efficiently.

What is Spring Boot Starters?

Moving ahead with the Spring Boot Interview Questions and Answers, it is important to know about Spring Boot Starters, which is one of the 4 major components of Spring Boot. To build a single application, there are a lot of dependencies in the Spring framework. Spring Boot Starter POMs are designed to reduce these dependencies into a single one.
Therefore, instead of going through a lot of data to find a sample code and copy the dependencies, Spring Boot Starters provides developers with a ready to use all in one set of dependencies.
Some of the Spring Boot Starters are Web Starter, Test Starter, Mail Starter, Data JPA Starter.
Jar dependencies can be added to Maven’s pom.xml or Gradle’s build.gradle file.

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>

How is Spring Boot architecture? Is it the same as Spring MVC?

Although Spring Boot is built as an architecture to Spring framework, it is not the same as Spring MVC, nor is a substitution to the latter one.
In simple words, Spring Boot is a mediator that helps a developer to connect, configure, and develop more easily and efficiently with the Spring framework.
Some of the auto configuration files provided by Spring Boot are database config, security config, and security config, which saves essential development time. Moreover, there are features such as Spring Boot Starters, which cannot to found in Spring MVC.

How can you override default properties in Spring boot Project?

Spring boot provides a lot of properties which can be overridden by specifying them in application.properties.

For example: You want to specify prefix and suffix in Spring MVC applications. You can simply do it by putting below properties in application.properties.

spring.mvc.view.prefix: /WEB-INF/
spring.mvc.view.suffix: .jsp

What are disadvantages of Spring boot?

If you want to convert your old spring application to Spring boot application, it may not be straight forward and can be time consuming.

How to Deploy Spring Boot Web Applications as Jar and War Files?

Traditionally, we package a web application as a WAR file and then deploy it into an external server. Doing this allows us to arrange multiple applications on the same server. When CPU and memory were scarce, this was a great way to save resources.

But things have changed. Computer hardware is fairly cheap now, and the attention has turned to server configuration. A small mistake in configuring the server during deployment may lead to catastrophic consequences.

Spring tackles this problem by providing a plugin, namely spring-boot-maven-plugin, to package a web application as an executable JAR.

To include this plugin, just add a plugin element to pom.xml:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
With this plugin in place, we'll get a fat JAR after executing the package phase. This JAR contains all the necessary dependencies, including an embedded server. So, we no longer need to worry about configuring an external server.

We can then run the application just like we would an ordinary executable JAR.

Notice that the packaging element in the pom.xml file must be set to jar to build a JAR file:

<packaging>jar</packaging>
If we don't include this element, it also defaults to jar.

To build a WAR file, we change the packaging element to war:

<packaging>war</packaging>
and leave the container dependency off the packaged file:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
After executing the Maven package phase, we'll have a deployable WAR file.

Why did you use Spring boot in your application?

As discussed earlier, Spring boot makes it easier for you to create Spring application, it can save a lot of time and efforts.

For example: Let’s say you want to create Spring boot project with activeMQ. You can simply use "spring–boot–starter–activemq" as artifact Id, it will take all the defaults and create Spring application with ActiveMQ configured. Let’s say you don’t want to use inbuilt activeMQ, you can simply override "spring.activemq.broker-url" in application.properties to use external ActiveMQ.

What Is Spring Initializr?

Spring Initializr is a convenient way to create a Spring Boot project.

Can you explain what happens in the background when a Spring Boot Application is “Run as Java Application”?

When a Spring Boot application is executed as “Run as Java application”, then it automatically launches up the tomcat server as soon as it sees, that you are developing a web application.

How to create a Spring Boot application using Spring Initializer?

It is a web tool provided by Spring on its official website. However, you can also create Spring Boot project by entering project details.

Mention some advantages of Spring Boot

Here are some major advantages of using spring-boot:

1. Helps you to create a stand-alone application, which can be started using java.jar.
2. It offers pinpointed‘started' POMs to Maven configuration.
3. Allows you to Embed Undertow, Tomcat, or Jetty directly.
4. Helps you to configure spring whenever possible automatically.

Explain the term 'Spring Boot'.

It is a Spring module that offers Rapid Application Development to Spring framework. Spring module is used to create an application based on Spring framework which requires to configure few Spring files.

Search
R4R Team
R4R provides Spring Boot Freshers questions and answers (Spring Boot Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Spring boot interview question for fresher,Spring Boot Freshers & Experienced Interview Questions and Answers,Spring Boot Objetive choice questions and answers,Spring Boot Multiple choice questions and answers,Spring Boot objective, Spring Boot questions , Spring Boot answers,Spring Boot MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Spring Boot fresher interview questions ,Spring Boot Experienced interview questions,Spring Boot fresher interview questions and answers ,Spring Boot Experienced interview questions and answers,tricky Spring Boot queries for interview pdf,complex Spring Boot for practice with answers,Spring Boot for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .