Youtube Link: https://youtu.be/CXTiwkZVoZI
( Microservices Architecture Training: https://www.edureka.co/microservices-architecture-training )
This Edureka's PPT on Spring Boot Interview Questions talks about the top questions asked related to Spring Boot.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
11. Question 3
Spring Boot
Interview Questions
www.edureka.co
WhataretheadvantagesofSpring
Boot?
Advantages of Spring Boot
01 Provides autoconfiguration to load a set of default configuration for a quick start
of the application
02Creates stand-alone applications with a range of non-functional features that are
common to large classes of project
03 Spring Boot comes with embedded tomcat, servlet containers jetty to avoid the
usage of WAR files
04Spring Boot provides an opinionated view to reduce the developer effort and
simplify maven configurations
12. Question 3
Spring Boot
Interview Questions
www.edureka.co
WhataretheadvantagesofSpring
Boot?
Advantages of Spring Boot
05 Provides CLI tool to develop and test applications
06Comes with Spring Boot starters to ensure dependency management and also
provides various security metrics
07 Consists of a wide range of APIs for monitoring and managing applications in dev
and prod.
08Integrates with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data,
Spring Security easily by avoiding boilerplate code.
31. Question 12
Spring Boot
Interview Questions
www.edureka.co
Thymeleaf is a server-side Java template engine used
forwebapplications.
Itaims to bringnaturaltemplatefor yourwebapplication andcan integrate
well with Spring Framework and HTML5 Java web
applications.
Whatisthymeleafandhowtouse
thymeleaf?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-
thymeleaf</artifactId>
</dependency>
40. Question 15
Spring Boot
Interview Questions
www.edureka.co
Spring Initializer isawebtoolprovidedbySpring.Withthe
helpofthistool,youcancreateSpringBootprojectsbyjust
providingprojectdetails.
Mentionthestepstocreatea
SpringBootprojectusing
Spring Initializer
41. Question 15
Spring Boot
Interview Questions
www.edureka.co
Mentionthestepstocreatea
SpringBootprojectusing
Spring Initializer
✓ Choose the maven project and the required dependencies. Then, fill
the other required details like Group, Artifact, and then click on
GenerateProject.
✓ Once the project is downloaded, extract the project on to your
system
✓ Next, you have to import this project using the import option on the
SpringToolSuiteIDE
43. Question 16
Spring Boot
Interview Questions
www.edureka.co
SpringBootstarterprojectsprovidetherequiredlibrariesto
connecttheapplicationwithJDBC.
So,forexample,ifyoujusthavetocreateanapplication and
connectitwithMYSQLdatabase,youcanfollowthebelowsteps:
Mentionthestepstoconnect
SpringBootapplicationtoa
databaseusingJDBC
Step 1: Create a database in MySQL
CREATE DATABASE example;
Step 2: Create a table inside this database
CREATE TABLE customers(customerid INT PRIMARY KEY
NOT NULL AUTO_INCREMENT, customername
VARCHAR(255));
44. Question 16
Spring Boot
Interview Questions
www.edureka.co
Mentionthestepstoconnect
SpringBootapplicationtoa
databaseusingJDBC
Step 3: Create a Spring Boot project and provide
the required details
Step 4: Add JDBC, MySQL and web dependencies.
spring.datasource.url=jdbc:mysql://localhost:3306/e
xample
spring.datasource.username=root
spring.datasource.password=mysql
spring.jpa.hibernate.ddl-auto=create-drop
Step 5: Once the project is created, you have to
configure the database into application
properties.
45. Question 16
Spring Boot
Interview Questions
www.edureka.co
Mentionthestepstoconnect
SpringBootapplicationtoa
databaseusingJDBC
Step 6: The main application.java class should have
the following code:
package com.edureka;
import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootAp
plication;
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class,
args);
}
}
46. Question 16
Spring Boot
Interview Questions
www.edureka.co
Mentionthestepstoconnect
SpringBootapplicationtoa
databaseusingJDBC
Step 7: You have to create a controller to handle
the HTTP requests, by mentioning the following
code:
package com.edureka;
Import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class JdbcController {
@Autowired
JdbcTemplate jdbc;
@RequestMapping("/insert")
public String index(){
jdbc.execute("insert into customers(name)values('Aryya')");
return "Data Entry Successful";
}
}
47. Question 16
Spring Boot
Interview Questions
www.edureka.co
Mentionthestepstoconnect
SpringBootapplicationtoa
databaseusingJDBC
Step 8: Finally execute this project as a Java
application.
Step 9: Open the URL (localhost:8080/insert), and you
will see the output as data entry successful.
You can also go forward and check if the data is
entered into the table.
84. Spring Boot
Interview Questions
www.edureka.co
Question 31 TheadvantagesoftheYAMLfilethanapropertiesfileisthatthedatais
storedinahierarchicalformat.
So,itbecomesveryeasyforthedeveloperstodebugifthereisanissue.
TheSpringApplicationclasssupportstheYAMLfileasanalternative to
propertieswheneveryouusetheSnakeYAMLlibraryonyourclasspath.
The different ways to load a YAML file in Spring
Boot is as follows:
➢ UseYamlMapFactoryBeantoloadYAMLasaMap
➢ UseYamlPropertiesFactoryBean toloadYAMLasProperties
MentiontheadvantagesofYAML
filethanPropertiesfileandthe
different waystoloadYAMLfilein
Springboot
95. Spring Boot
Interview Questions
www.edureka.co
Question 36
Howdoespath=”sample”,
collectionResourceRel=”sample”
workwithSpringDataRest?
@RepositoryRestResource(collectionResourceRel =
"sample", path = "sample")
public interface SampleRepository extends
PagingAndSortingRepository<Sample, Long>
➢ path – This section is used to mention the segment under
whichtheresourceistobeexported.
➢ collectionResourceRel – This value is used to
generatelinkstothecollectionresource.
99. Spring Boot
Interview Questions
www.edureka.co
Question 38
SinceSpringBootsupports Log4j2 for logging a
configuration,youhavetoexclude Logback and
include Log4j2 for logging.Thiscanbeonlydoneifyouare
usingthestartersproject.
HowdoyouConfigureLog4jfor
logging?
103. Spring Boot
Interview Questions
www.edureka.co
Question 40
ProfilesinSpringprovidesawaytosegregatethepartsofthe
applicationconfigurationandmakesitavailableinenvironments.So,
basically,any@Component or a @Configuration can
bemarkedwitha@Profiletolimitasitisloaded.
Whatdoyouthinkistheneedfor
Profiles?
109. Spring Boot
Interview Questions
www.edureka.co
Question 43 Spring Data REST isnotrecommendedinreal-world
applicationsasyouareexposingyourdatabaseentities directly
asRESTservices.
WhiledesigningRESTfulservices,thetwomostimportantthingsthat
weconsideristhedomainmodelandtheconsumers.
But,whileusingSpringDataREST,noneoftheseparametersare
considered.Theentitiesaredirectlyexposed.
UseSpringDataREST,for the initial evolution of the
project.
WhyisSpringDataRESTnot
recommendedinreal-world
applications?
115. Spring Boot
Interview Questions
www.edureka.co
Question 45
Whatisthewaytouseprofilesto
configuretheenvironment-
specificconfigurationwithSpring
Boot?
Since its a known fact that a Profile is nothing but a key to identify
an environment lets consider the following two profiles in the
example:
•dev
•Prod
Consider the following properties present in the application
propertiesfile:
example.number: 100
example.value: true
example.msg: Dynamic Message
116. Spring Boot
Interview Questions
www.edureka.co
Question 45
Whatisthewaytouseprofilesto
configuretheenvironment-
specificconfigurationwithSpring
Boot?
Now, say you want to customize the application.properties for dev
profile, then you need to create a file with name application-
dev.properties and override the properties that you want to
customize.
Youcanmentionthefollowingcode:
example.msg: Dynamic Message in Dev
Similarly,ifyouwanttocustomizetheapplication.properties forprod
profile,thenyoucanmentionthefollowingcodesnippet:
example.msg: Dynamic Message in Prod
117. Spring Boot
Interview Questions
www.edureka.co
Question 45
Whatisthewaytouseprofilesto
configuretheenvironment-
specificconfigurationwithSpring
Boot?
Once you are done with the profile-specific configuration, you
havetosettheactive profileinanenvironment.
Todothat, either youcan:
✓ Use-Dspring.profiles.active=prod in arguments
✓ Usespring.profiles.active=prodinapplication.propertiesfile
127. Spring Boot
Interview Questions
www.edureka.co
Question 49
WhatisthenameofthedefaultH2
databaseconfiguredbySpring
Boot?
ThenameofthedefaultH2databaseistestdb
spring.datasource.name=testdb # Name of the
datasource.
Note:Justin-caseifyouareusingH2in-memorydatabase,thenexactly
thatisthenameofSpringBootwhichisusedtosetupyourH2database.