Master Spring Boot with 59 Essential Interview Questions!
Master Spring Boot with 59 Essential Interview Questions!
Spring-Boot
1)What is Spring Boot?
➔-Spring Boot is an open-source framework built on top of the spring
framework for java developers.
-Spring Boot was developed by Pivotal Software(now the part of VMware),
It was first released in 2014.
-In Spring Boot, ‘Boot’ refers to the concept of rapidly initializing a spring
application by handling all essentials set-ups and configuration.
2)What is Framework?
➔Framework is a software that is built on the top of one or more
technologies to simplify the application development process by
generating the common logics of the application dynamically.
5)What is the difference between dependent jar file and relevant jar file?
➔-Dependent JAR:- A JAR file that your application must have to run or
compile — like Spring libraries if you're using Spring Boot.
-Relevant JAR:- A JAR file that is related or useful to your project, but not
always required — like an email library if your app sends emails.
6)Define @SpringBootApplication?
➔i)@Configuration:-This annotation in Spring indicates that the class can
be used to define bean configuration within the Spring application context.
ii)@ComponentScan:-It tells Spring to scan the specified package and it’s
sub packages for component, configuration and service to manage.
iii)@EnableAutoConfiguration:-It automatically configures the Spring
application based on its dependencies and the contents of the classpath.
-@SpringBootApplication annotation serves as the “Entry point for a
SpringBoot application.
vi)Message Starter
vii)Batch Starter
Web Server You have to set up Tomcat/ Comes with built-in Tomcat,
Jetty separately ready to run apps
Dependencies You add each dependeny Comes with Spring Boot
manually Starter(pre-made set of
dependencies)
Project You have to create and Spring Boot creates
Structure organize folders,files Structure automatically
Learning Require more time to learn Easier for beginners and
Curve and configure faster development
Focus Gives full control, more Focuses on productivity and
Created by:-Lalit Ingale
flexible simplicity
Run method Needs XMl/config files+WAR Just run your main() method
deployment ,like a normal Java program
Focus Gives full control, more Focuses on productivity and
flexible simplicity
iii)@Resource:-Alternate to @Autowired+@Qualifier
25)What is lombok?
Created by:-Lalit Ingale
➔Lombok is a Java tool that helps you write less code. It automatically
adds things like getters, setters, constructors, and more, so you don't have
to write them yourself.
26)Define @Data?
➔@Data is a shortcut from Lombok that saves you from writing a lot of
boring code in Java classes.
-When you use @Data it automatically creates Getters,Setters,toString(),
equals() and constructor.
29)We configure DAO class with @Service annotation and Service class
with @Repository Annotation?
➔ No, we should not configure a DAO class with @Service and a Service
class with @Repository. That’s a wrong usage of annotations.
- @Repository → used for DAO (Data Access Object) classes.
These classes interact with the database.
- @Service → used for Service classes.
These contain business logic.
➔As per Algorithm priority the Hikari CP Data Source will be taken for
AutoConfiguration.
35)What is RestTemplate?
➔ RestTemplate is a helper class provided by Spring that makes it easy to
call REST APIs (HTTP services) from your Spring Boot application.
36)What is webClient?
➔ WebClient is a modern and powerful tool in Spring used to make HTTP
calls to other APIs, just like RestTemplate, but with more features and
better performance.
37)Define @ConfigurationProperties?
➔- It’s a way to read values from your application.properties or
application.yml file and put them into a Java class automatically.
- So you don’t have to write @Value again and again for every property.
You just create one class, and Spring fills in all the values for you.
f)Common prefix for keys of properties f)Common prefix for keys in proper-
is not required. ties file is required.
g)The keys in properties file and the g)The keys in properties file and the
property name in spring bean class property name in spring bean class
need not to match. needs to match.
h)If we specify wrong key in @Value h)If the keys in properties file is not
annotation we get IllegalArgument- matching with spring bean property
Exception. name..then No Exception will be
raised it just ignore value injection
to that spring bean property.
i)Can be used to inject the values to i)Can be used to inject the values to
simple type,wrapper type,String type simple type,wrapper type,String type,
properties. array,collection HAS-A type spring
bean properties.
43)What is YML/YAML?
➔-YAML stands for Yet Another Markup Language.
-It is a simple, human-readable format used for writing configuration files.
48)What is Profiles?
➔A profile is like a label or a tag that tells Spring which settings or code to
51)How many ways are there to activate profiles in spring boot app?
Created by:-Lalit Ingale
54)What is the difference between not adding @Profile for spring bean
and adding @Profile(“default”) for spring bean?
➔-If @Profile is not added for spring bean that will work for all profiles
when profile is activated..It will even work if no profile activated and also
for child profile that is activated eg:service,controller class.
-@Profile(“default”) based spring bean will work only when active profiles
are not specified.
Created by:-Lalit Ingale
55)What is Runners?
➔ Runners are special blocks of code that run automatically when your
Spring Boot application starts — right after everything is set up.
58)Though, we are not adding any starters to Spring boot project, How
does it gets multiple jar files as the maven/gradle dependencies to the
Project?
➔In every Spring boot Project, One parent spring boot project will be
imported from the maven central repo using<parent>tag.
➔Based on the parent spring boot project’s version, lots of things will
come to our spring boot project which is nothing but a child project.
a)Basic spring,spring boot jar files and dependent, relavent jar files.
b)required plugins
c)required Project Properties.