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

How to implement JWT authentication for Spring Boot Application?

JWT stands for JSON Web Token. JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. The client will need to authenticate with the server using the credentials only once. During this time the server validates the credentials and returns the client a JSON Web Token(JWT). For all future requests the client can authenticate itself to the server using this JSON Web Token(JWT) and so does not need to send the credentials like username and password.

Posted Date:- 2021-08-25 07:53:05

What is Thymeleaf and how to use it?

Thymeleaf is a server-side template engine for a web application. Its main purpose is to bring natural templates to the web application.

Specifically, one has to include the dependency spring-boot-starter-thymeleaf in the application to use thymeleaf.

Posted Date:- 2021-08-25 07:51:27

How to disable specific auto-configuration?

To disable any specific auto-configuration, one can use exclude attribute for @EnableAutoConfiguration annotation.

@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class SampleApplication

Posted Date:- 2021-08-25 07:50:08

Why do we use the annotation @SpringBootApplication in the main Spring Boot application class?

For applications to use auto-configuration, component scans, and extra configurations, one can include one single annotation @SpringBootApplication. This annotation includes three annotations @EnableAutoConfiguration, @ComponentScan, and @Configuration.

@EnableAutoConfiguration – enable Spring Boot’s auto-configuration
@ComponentScan – this allows scanning the packages where the application is located.
@Configuration – allow registering extra beans in the context or import additional configuration classes.

Posted Date:- 2021-08-25 07:49:17

How would you set up an application with HTTPS port with Spring Boot?

By default, the Spring Boot application runs on HTTP port. To make your application run with HTTPS port, there are two ways.

One can use server.port, server.ssl.key-store-password,server.ssl.key-store ,server.ssl.key-store-type and server.ssl.key-alias.

Another way to use the HTTPS port is programmatically.

Posted Date:- 2021-08-25 07:48:04

How would you find out which auto-configurations Spring Boot applied on startup and which conditions it evaluated?

Spring Boot Actuator can provide that information, through HTTP or JMX endpoints. Alternatively, you can start-up your Spring Boot application with the "--debug" flag.

Do note, that the information on evaluated conditions is a bit "raw" and not easily digested. For that, read this guide to make sure you understand how Spring Boot’s auto-configurations work.

Posted Date:- 2021-08-25 07:46:58

What is the easiest way to deploy a Spring Boot application in production? What other options are there?

The simplest way to deploy your Spring Boot application is as a .jar file with an embedded servlet container, to any server or platform that has a JRE installed.
For organizational and historical reasons, you can also deploy your Spring Boot application as a .war file, into an existing servlet container or application server.

Last but not least, you can, of course, also put your .jar file into a Docker image and even deploy those with Kubernetes.

Posted Date:- 2021-08-25 07:46:21

Why do you not need to specify dependency versions in your pom.xml file when including 3rd party libraries? Does that hold true for all 3rd party libraries or only some? How can you find out what libraries Spring Boot supports?

This is because Spring Boot does some dependency management for you.

On a high-level, Spring Boot starters pull-in a parent pom.xml file (or a build.gradle file) which has all the dependencies and respective versions defined that a specific Spring Boot version supports - a so-called bill of materials. You can then simply use those pre-defined versions, or override the version numbers in your own build scripts.

You can find the list of all currently supported 3rd party libraries and versions in the spring-boot-dependencies project.

Posted Date:- 2021-08-25 07:43:35

Name two ways to create a new Spring Boot project from scratch? Also, how do you know what spring-boot-starters your project needs?

You can create new Spring Boot projects through the Spring Initializr web application or the Spring Boot CLI. Interestingly enough, Spring Initializr is not just a website where you can generate project skeleton .zip files. It is also an API, that you can programmatically call. All major IDEs (Spring Tool Suite, IntelliJ IDEA Ultimate, Netbeans and VSCode) directly integrate with it, so that you can create new Spring Boot projects right out of your IDE.

As for starters, you need to read the documentation and have a bit of experience. If working with a web application, you will start with spring-boot-starter-web and then add the appropriate starter from the documentation, once you want to include a certain technology. After a while, you will get a good feel for what starters you need for which technologies.

Posted Date:- 2021-08-25 07:39:34

What Spring Boot features help develop Microservices Applications?

Primarily used for developing microservices-based applications, Spring Boot offers the following key features for configuring, developing, and deploying microservices architecture.

Integrates a tool called the Actuator, which enables users to manage and monitor applications
Provides support for embedded servers, such as Jetty and Tomcat
Users can simply run war files, without deploying it
Includes an Auto-Configuration functionality, allowing users to configure Spring applications automatically
Supports HTTP client Feign

Posted Date:- 2021-08-25 07:38:03

Where do you find the class files when you compile a Maven project?

You will find the class files ${basedir}/target/classes/.

Posted Date:- 2021-08-25 07:36:27

Explain what is Maven artifact?

Usually an artifact is a JAR file which gets arrayed to a Maven repository. One or more artifacts a maven build produces such as compiled JAR and a sources JAR.

Each artifact includes a group ID, an artifact ID and a version string.

Posted Date:- 2021-08-25 07:35:21

Explain what is Maven? How does it work?

Maven is a project management tool. It provides the developer a complete build lifecycle framework. On executing Maven commands, it will look for POM file in Maven; it will run the command on the resources described in the POM.

Posted Date:- 2021-08-25 07:34:28

What does Aspect-Oriented Programming (AOP) mean?

Aspect Oriented Programming (AOP) supplements Object-Oriented Programming (OOP) by giving another mindset about program structure. The key unit of measured quality in OOP is the class, while in AOP the unit of particularity is the viewpoint. Angles empower the modularization of concerns, for example, transaction management that cut over numerous sorts and questions.

Posted Date:- 2021-08-25 07:33:35

List out the features of Spring Boot?

Few are the important features in Spring Boot
Spring initializer
Starter dependency

Posted Date:- 2021-08-25 07:31:31

Why do we use “Opinionated” in spring boot?

It takes after "Opinionated Defaults Configuration" Approach to lessen Developer exertion. Because of the Opinionated perspective of spring boot, what is required to begin yet additionally we can get out if not appropriate for the application. Spring Boot utilizes sensible defaults, “opinions,” for the most part in light of the classpath substance.

Posted Date:- 2021-08-25 07:30:41

What does Spring Boot Starter Pom mean? Why Is It Useful?

Starters are an arrangement of advantageous reliance descriptors that you can incorporate into your application. The starters contain a considerable amount of the dependencies that you have to get a task up and running rapidly and with a steady, supported a set of managed transitive conditions.

The starter POMs are helpful reliance descriptors that can be added to your application’s Maven. In another word, if you are building up a project that utilizes Spring Batch for batch preparing, you need to incorporate spring-boot-starter-bunch that will import all the required conditions for the Spring Batch application. This decreases the burden of looking at and designing all of the conditions required for a structure.

Posted Date:- 2021-08-25 07:29:28

Why is Spring Data REST not recommended in real-world applications?

Spring Data REST is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider is the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered. The entities are directly exposed. So, I would just say, you can use Spring Data REST, for the initial evolution of the project.

Posted Date:- 2021-08-25 07:28:42

What are the steps to add a custom JS code with Spring Boot?

Create a folder and name it static under the resources folder and you can put the static content in that folder. Just in case, the browser throws an unauthorized error, you either disable the security or search for the password in the log file, and eventually pass it in the request header.

Posted Date:- 2021-08-25 07:27:59

Explain steps to deploy an application on virtual machine.

Below are the steps to deploy application on virtual machine.

a). Install Java.
b). Install the Application Server.
d). Deploy the application war file.

Posted Date:- 2021-08-25 07:27:16

How is Hibernate chosen as the default implementation for JPA without any configuration?

When we use the Spring Boot Auto Configuration, automatically the spring-boot-starter-data-jpa dependency gets added to the pom.xml file. Now, since this dependency has a transitive dependency on JPA and Hibernate, Spring Boot automatically auto-configures Hibernate as the default implementation for JPA, whenever it sees Hibernate in the classpath.

Posted Date:- 2021-08-25 07:26:10

Mention the advantages of the YAML file than Properties file and the different ways to load YAML file in Spring boot.

The advantages of the YAML file than a properties file is that the data is stored in a hierarchical format. So, it becomes very easy for the developers to debug if there is an issue. The SpringApplication class supports the YAML file as an alternative to properties whenever you use the SnakeYAML library on your classpath. The different ways to load a YAML file in Spring Boot is as follows:

1. Use YamlMapFactoryBean to load YAML as a Map
2. Use YamlPropertiesFactoryBean to load YAML as Properties

Posted Date:- 2021-08-25 07:25:09

Is excluding package without using the basePackages filter is possible? How?

Yes. It is possible to exclude package without using the basePackages filter by simply using the exclude attribute while using the @SpringBootApplication annotation.

Posted Date:- 2021-08-25 07:21:21

How can you set active profile in Spring Boot?

Follow the following methods to set an active profile in Spring Boot.

1. Pass this profile as an argument when you launch the Spring Boot application.
2. Set active the active profile in application.properties file.

Posted Date:- 2021-08-25 07:19:40

What is the default package in Spring Boot?

A class without any package declaration is considered as a default package.

Posted Date:- 2021-08-25 07:17:41

Why Do We Need Spring Profiles?

When developing applications for the enterprise, we typically deal with multiple environments such as Dev, QA and Prod. The configuration properties for these environments are different.

For example, we might be using an embedded H2 database for Dev, but Prod could have the proprietary Oracle or DB2. Even if the DBMS is the same across environments, the URLs would definitely be different.

To make this easy and clean, Spring has the provision of profiles to help separate the configuration for each environment. So, instead of maintaining this programmatically, the properties can be kept in separate files such as application-dev.properties and application-prod.properties. The default application.properties points to the currently active profile using spring.profiles.active so that the correct configuration is picked up.

Posted Date:- 2021-08-25 07:16:59

Can you explain how to deploy to a different server with Spring Boot?

To deploy a different server with Spring Boot: Generate a WAR from the project and then, deploy the WAR file onto your favorite server. The steps to deploy the WAR file on the server is dependent on the server you choose.

Posted Date:- 2021-08-25 07:16:19

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

while a Spring Boot app is executed as “Run as Java Application, then it routinely launches up the tomcat server and deploys the application automatically.

Posted Date:- 2021-08-25 07:15:47

How Exception Handling implement using Spring Boot?

Spring boot has a very useful way to do this. ControllerAdvice used to handle exceptions in Spring Boot. This will be implemented everywhere where it handles all exceptions thrown by the controller class.

Posted Date:- 2021-08-25 07:14:55

Can you give an example for ReadOnly as true in Transaction management?

Example for ReadOnly as TRUE in transaction management could be as follows: Consider a scenario, where you have to read data from the database. For example, let us say you have a customer database, and you want to read the customer details such as customerID, and customername. To do that, you will set read-only on the transaction as we do not want to check for the changes in the entities.

Posted Date:- 2021-08-25 07:14:24

Explain CORS in Spring Boot?

CORS stands for Cross-Origin Resource Sharing is a mechanism implemented by browsers and helps users to authorize cross-domain requests. This mechanism serves as an alternative to less secure and less powerful hacks of the kinds of IFrame or JSONP.

Posted Date:- 2021-08-25 07:13:19

Define apache freemarker.

Freemarker is a Java-based template used to generate plain text, emails, HTML file, etc.

Posted Date:- 2021-08-25 07:12:54

What is Cross-Site Request Forgery attack?

Cross-Site Request Forgery attack or one-click attack is an attack that forces other users to execute malicious commands on the application. CSRF attack specifically targets state-changing requests.

Posted Date:- 2021-08-25 07:12:28

Can we disable the default web server in the Spring Boot application?

The major strong point in Spring is to provide flexibility to build your application loosely coupled. Spring provides features to disable the web server in a quick configuration. Yes, we can use the application.properties to configure the web application type, i.e. spring.main.web-application-type=none.

Posted Date:- 2021-08-25 07:11:36

Is this possible to change the port of Embedded Tomcat server in Spring boot?

Yes, it's possible to change the port. You can use the application.properties file to change the port. But you need to mention "server.port" (i.e. server.port=8081). Make sure you have application.properties in your project classpath; REST Spring framework will take care of the rest. If you mention server.port=0 , then it will automatically assign any available port.

Posted Date:- 2021-08-25 07:10:41

What is a shutdown in the actuator?

Shutdown is an endpoint that allows the application to be gracefully shutdown. This feature is not enabled by default. You can enable this by using management.endpoint.shutdown.enabled=true in your application.properties file. But be careful about this if you are using this.

Posted Date:- 2021-08-25 07:10:00

Define ELK stack.

The ELK Stack is made of three open-source products: 1) Elasticsearch, 2) Logstash, and 3) Kibana.

1) Elasticsearch: It is a NoSQL database which is based on the open-source search engine called Lucene.
2) Logstash: It is a data processing pipeline tool which accepts inputs from sources, performs different transformations, and exports the data to targets.
3) Kibana: Kibana helps users to visualize data with graphs and chart in Elasticsearch.

Posted Date:- 2021-08-25 07:09:20

Explain Docker in Spring Boot.

It is a tool designed to create, deploy, and run a project by using containers.

Posted Date:- 2021-08-25 07:08:21

Explain overriding default properties in Spring Boot application.

Spring Boot has lots of properties that can be easily overridden by specifying them in application.properties.

Posted Date:- 2021-08-25 07:07:53

How to enable logging in Spring Boot?

In order to enable debug logging, you can specify --debug while starting the application from the command prompt.

Posted Date:- 2021-08-25 07:07:25

What does @Grab annotation do? When to use this?

The @Grab annotation is used to import types which Spring boot CLI cannot resolve automatically. It actually extends @Grab annotation from Gradle, a JAR dependency manager into Groovy, so that, for many frequently used library you can import them by just adding module ID like you can just write @Grab("h2") instead of @Grab("com.h2database:h2:1.4.185) to import H2 in-memory database and Spring CLI will take care of version, etc.

Posted Date:- 2021-08-25 07:05:50

Can you write Spring application with Groovy?

Yes, Spring Boot CLI makes it possible to write Spring Boot application in Groovy. It also cut down a lot of noise which comes with writing code in Java.

Posted Date:- 2021-08-25 07:05:21

How do you secure the Spring Boot Actuator's endpoint to restrict access?

Just like Spring MVC application, you can secure the Spring Boot Actuator's endpoints using Spring Security. You can add a Security starter as a build dependency and then security auto-configuration will take care of locking the application, including the Actuator endpoints.

Posted Date:- 2021-08-25 07:04:57

What Basic Annotations Does Spring Boot Offer?

The primary annotations that Spring Boot offers reside in its org.springframework.boot.autoconfigure and its sub-packages.

Here are a couple of basic ones:

@EnableAutoConfiguration – to make Spring Boot look for auto-configuration beans on its classpath and automatically apply them
@SpringBootApplication – to denote the main class of a Boot Application. This annotation combines @Configuration, @EnableAutoConfiguration and @ComponentScan annotations with their default attributes.

Posted Date:- 2021-08-25 07:03:06

Explain Auto-Configuration in Spring Boot.

Auto-configuration is used to configure Spring application automatically based on dependencies of classpath parameter. It makes development faster and easier.

Posted Date:- 2021-08-25 07:00:17

What do you understand by Spring Boot supports relaxed binding?

Relaxed binding, is a way in which, the property name does not need to match the key of the environment property. In Spring Boot, relaxed binding is applicable to the type-safe binding of the configuration properties. For example, if a property in a bean class with the @ConfigurationPropertie annotation is used sampleProp, then it can be bounded to any of the following environment properties:

a) sampleProp
b) sample-Prop
c) sample_Prop

Posted Date:- 2021-08-25 06:59:43

Mention the dependencies needed to start up a JPA Application and connect to in-memory database H2 with Spring Boot?

The dependencies are needed to start up a JPA Application and connect to in-memory database H2 with Spring Boot

web starter
data JPA starter
To include the dependencies refer to the following code:


Posted Date:- 2021-08-25 06:57:19

How to exclude any package without using the basePackages filter?

There are different ways you can filter any package. But Spring Boot provides a trickier option for achieving this without touching the component scan. You can use the exclude attribute while using the annotation @SpringBootApplication. See the following code snippet:

@SpringBootApplication(exclude= {Employee.class})
public class FooAppConfiguration {}

Posted Date:- 2021-08-25 06:55:55

What is the error you see if H2 is not in the classpath?

If H2 is not present in the classpath, then you see the following error:

To resolve this error, add H2 to the pom.xml file, and restart your server.
The following code snippet can be added to add the dependency:


Posted Date:- 2021-08-25 06:54:36

How to instruct an auto-configuration to back off when a bean exists?

To instruct an auto-configuration class to back off when a bean exists, you have to use the @ConditionalOnMissingBean annotation. The attributes of this annotation are as follows:

a) value: This attribute stores the type of beans to be checked
b) name: This attribute stores the name of beans to be checked

Posted Date:- 2021-08-25 06:53:51

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 experienced,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 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 .