YouTube Icon

Interview Questions.

Top 27 Spring Boot Interview Questions - Jul 28, 2022

fluid

Top 27 Spring Boot Interview Questions

Q1. What Is Name Of The Configuration File Which You Use In Spring Boot?

Configuration document utilized in Spring boot initiatives is application.Houses. It may be very critical report as it is used to override all default configurations.

Q2. What Are Embedded Containers Which Are Supported By Spring Boot?

Spring boot contains embedded Tomcat, Jetty and undertow servers.

Q3. What Embedded Containers Does Spring Boot Support?

Spring Boot consists of support for embedded Tomcat, Jetty, and Undertow servers. By default the embedded server will concentrate for HTTP requests on port 8080.

Q4. Why Did You Use Spring Boot In Your Application?

As mentioned in advance, Spring boot makes it less difficult in an effort to create Spring utility, it is able to store numerous time and efforts.

For example: Let’s say you want to create Spring boot venture with activeMQ. You can absolutely use “spring–boot–starter–activemq” as artifact Id, it's going to take all of the defaults and create Spring software with ActiveMQ configured. Let’s say you don’t want to use in-built activeMQ, you can honestly override “spring.Activemq.Broker-url” in application.Residences to apply external ActiveMQ.

Q5. What Is Devtools In Spring Boot?

Spring boot comes with DevTools that is brought to growth the productiveness of developer. You don’t need to set up your utility each time you make the modifications.Developer can truely reload the adjustments with out restart of the server. It avoids ache of deploying software each time when you make any change. This module might be disabled in production surroundings.

Q6. How Can You Override Default Properties In Spring Boot Project?

Spring boot gives a variety of properties which may be overridden by specifying them in application.Homes.

For example: You want to specify prefix and suffix in Spring MVC applications. You can genuinely do it via placing under residences in software.Houses.

Spring.Mvc.View.Prefix: /WEB-INF/

spring.Mvc.View.Suffix: .Jsp

Q7. How To Reload My Changes On Spring Boot Without Having To Restart Server?

Include following maven dependency within the application.

<dependency>

 <groupId>org.Springframework</groupId>

 <artifactId>springloaded</artifactId>

 <version>1.2.6.RELEASE</version>

</dependency>

Automatic restart

Applications that use spring-boot-devtools will robotically restart whenever documents at the classpath trade. This may be a useful characteristic when working in an IDE because it gives a very fast comments loop for code adjustments. By default, any entry on the classpath that factors to a folder will be monitored for changes.

<dependency>

<groupId>org.Springframework.Boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>actual</optional>

</dependency>

This may be executed the use of DEV Tools. With this dependency any modifications you store, the embedded tomcat will restart. Spring Boot has a Developer gear (DevTools) module which helps to enhance the productivity of builders. One of the important thing mission for the Java builders is to car installation the record modifications to server and vehicle restart the server. Developers can reload modifications on Spring Boot while not having to restart my server. This will gets rid of the want for manually deploying the modifications every time. Spring Boot doesn’t have this feature when it has released it’s first version. This turned into a maximum requested features for the developers. The module DevTools does precisely what is wanted for the builders. This module could be disabled inside the production environment.

Q8. What Is The Difference Between An Embedded Container And A War?

There isn't any force to move field less

Embedded field is simply one characteristic of Spring Boot

Traditional WAR also blessings lots from Spring Boot

Automatic Spring MVC setup, inclusive of DispatcherServlet

Sensible defaults primarily based on the classpath content

Embedded field may be used during improvement.

Q9. Can We Use Spring Boot With Applications Which Are Not Using Spring?

No, it is not viable as of now. Spring boot is restricted to Spring packages handiest.

Q10. How To Implement Spring Web Using Spring Boot?

Web Application Convenience 

Boot automatically configures

A DispatcherServlet & ContextLoaderListener

Spring MVC the use of equal defaults as @EnableWebMvc

Plus many useful more functions:

Static sources served from classpath

/static, /public, /assets or /META-INF/resources

Templates served from /templates

If Velocity, Freemarker, Thymeleaf, or Groovy on classpath

Provides default /errors mapping

Easily overridden

Default MessageSource for I18N

Q11. How Can You Run Spring Boot Application On Custom Port?

You can certainly positioned server.Port residences in software.Houses.

For instance:server.Port=8050.

Q12. What Is Spring Boot Starter And How It Is Useful?

Spring boot comes with plenty of starters which is about of handy dependency descriptors which you could consist of on your pom.Xml.

For example: Let’s say you want to work Spring MVC application, you could honestly include “spring–boot–starter–web” as dependency in pom.Xml .

Q13. What Are The Advantages Of Using Spring Boot?

It is very clean to broaden Spring Based programs with Java or Groovy.

It reduces lots of development time and increases productivity.

It avoids writing masses of boilerplate Code, Annotations and XML Configuration.

It could be very smooth to combine Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.

It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort

It gives Embedded HTTP servers like Tomcat, Jetty and so forth. To expand and check our internet programs very effortlessly.

It presents CLI (Command Line Interface) tool to broaden and test Spring Boot (Java or Groovy) Applications from command spark off very easily and fast.

It affords plenty of plugins to broaden and take a look at Spring Boot Applications very without problems the usage of Build Tools like Maven and Gradle

It gives plenty of plugins to paintings with embedded and in-memory Databases very without difficulty.

Q14. Have You Used Activemq In Spring Boot Application? Do You Know How To Configure External Activemq?

Spring Boot comes with embedded ActiveMQ.We want to use “spring–boot–starter–activemq” dependency in pom.Xml and it will deal with all defaults and could configure ActiveMQ within the assignment.

If you want to configure external ActiveMQ then you definitely want to just placed “spring.Activemq.Dealer-url” in software.Homes and offer the URL of external ActiveMQ.

Q15. What Is Spring Boot?

First of all Spring Boot isn't a framework, it's miles a way to ease to create stand-alone utility with minimum or zero configurations. It is technique to develop spring based software with very less configuration. It provides defaults for code and annotation configuration to quick begin new spring tasks within no time. It leverages current spring projects as well as Third birthday party tasks to increase manufacturing geared up applications. It affords a set of Starter Pom’s or gradle build files which you may use to add required dependencies and also facilitate automobile configuration.

Spring Boot automatically configures required instructions relying at the libraries on its classpath. Suppose your software need to have interaction with DB, if there are Spring Data libraries on magnificence route then it routinely units up connection to DB along side the Data Source class.

Q16. How Are Properties Defined? Where?

In spring boot, we must outline homes inside the utility.Residences record exists in classpath of utility as comply with.

Example: configure default DataSource bean.

Database.Host=localhost

database.User=admin

Q17. What Is Yaml?

Yaml Ain’t a Markup Language

Recursive acronym

Created in 2001

Alternative to .Homes files

Allows hierarchical configuration

Java parser for YAML is called SnakeYAML

Must be in the classpath

Provided by spring-boot-starters.

Q18. How Does It Work? How Does It Know What To Configure?

Auto-configuration works by way of studying the classpath

If you forget a dependency, Spring Boot can’t configure it

A dependency management device is recommended

Spring Boot parent and starters make it a good deal less complicated

Spring Boot works with Maven, Gradle, Ant/Ivy

Our content here will display Maven.

Q19. What Is The Configuration File Name Used By Spring Boot?

The configuration document utilized in spring boot tasks is application.Residences. This document is very crucial wherein we'd over write all of the default configurations. Normally we have to hold this file beneath the assets folder of the mission.

Q20. How Can You Implement Spring Security In Spring Boot Application?

Implementation of Spring safety in Spring boot utility requires little or no configuration. You want to feature spring-boot-starter-protection starter in pom.Xml.You want to create Spring config elegance so one can enlarge WebSecurityConfigurerAdapter and override required technique to attain protection in Spring boot utility.

Q21. What Is Actuator In Spring Boot?

Spring Boot Actuator is a sub-project of Spring Boot. It provides several manufacturing grade services in your application with little attempt on your element. There also are has many capabilities added for your utility out-of-the-container for coping with the provider in a production (or different) surroundings. They’re mainly used to reveal extraordinary styles of information about the walking application – health, metrics, data, dump, env and many others.

Q22. How To Implement Security For Spring Boot Application ?

Add spring protection starter to the boot software

<dependency>

   <groupId>org.Springframework.Boot</groupId>

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

  </dependency>

Q23. What Is A Spring Boot Starter Pom? Why Is It Useful?

Starters are a hard and fast of handy dependency descriptors that you can consist of on your application. The starters include a whole lot of the dependencies that you want to get a task up and jogging fast and with a regular, supported set of controlled transitive dependencies.

The starter POMs are convenient dependency descriptors that can be introduced on your application’s Maven. In easy phrases, if you are growing a undertaking that makes use of Spring Batch for batch processing, you simply have to encompass spring-boot-starter-batch in order to import all the required dependencies for the Spring Batch application. This reduces the weight of searching and configuring all of the dependencies required for a framework.

Q24. How To Run Spring Boot Application To Custom Port ?

In software.Properties, add following assets.

Server.Port = 8181.

Q25. What Are The Disadvantages Of Using Spring Boot?

It could be very tough and time eating method to transform current or legacy Spring Framework projects into Spring Boot Applications. It is relevant only for present day/Greenfield Spring Projects.

Q26. How To Configure Datasource Using Spring Boot?

Use either spring-boot-starter-jdbc or spring-boot-starterdata-jpa and consist of a JDBC motive force on classpath

Declare homes:

spring.Datasource.Url=jdbc:mysql://localhost/check

spring.Datasource.Username=dbuser

spring.Datasource.Password=dbpass

spring.Datasource.Motive force-magnificence-name=com.Mysql.Jdbc.Driver

Spring Boot will create a DataSource with properties set

Will even use a connection pool if the library is determined at the classpath.

Q27. Can You Control Logging With Spring Boot? How?

Yes, we are able to manipulate logging with spring boot.

Customizing default Configuration for Logging:

By adding logback.Xml document to the application we will override the default logging configuration providing by way of the Spring Boot. This file place inside the classpath (src/main/sources) of the application for Spring Boot to choose the custom configuration.

Spring Boot can manage the logging level

Just set it in utility.Homes

Works with most logging frameworks

 Java Util Logging, Logback, Log4J, Log4J2

logging.Stage.Org.Springframework=DEBUG

logging.Degree.Com.Acme.Your.Code=INFO




CFG