In this article, we will discuss some important 10 interview questions in Spring Boot. These the entire question is trending with building strong java career in the job market.
1) What is the use of @SpringBootApplication annotation and what is does internally?
As per Spring Boot documentation, @springBootapplication annotation, is combination of @ComponentScna, @EnableAutoConfiguration, and @Configuration annotations with their default values.
Spring boot enables the user to use single annotation, instead-of multiple annotations. @SpringBootApplication also provides the customize settings using different attributes like exclude (to exclude the auto-configuration classes), basePackages to provide base-package name for component scan.
2) What are the Advantages of Spring Boot?
Main Advantages of Spring boot are:
3) Different possible external configuration sources for spring boot:
Spring boot multiple ways to externalize the spring boot configuration, spring boot can read configuration either properties file or from yaml files. Below are the different ways to read configuration:
4) What is Spring Boot dependency management?
For spring boot applications, we can use spring-boot-parent, where we don’t need to specify the versions for spring-boot-starter, it will automatically resolves version from parent pom file.
5) How to change the application port and context-path of spring-boot application?
We can specify the server.port key for specifying the application port, if we are using profile, then we can also specify or override the for the specific profile in application-{profile}.properties(.yaml) with same key.
server.servlet.context-path is key used to specify the application context path, by default all spring boot application are deployed as root application.
6) What are the spring-boot dev-tools and what are its uses?
Spring boot Dev tools are an elaborated set of tools, which will help developer in developing the application easier, it will automatically re-deploy the application whenever developer made changes with less time.
Spring boot dev-tools uses two class loaders, one for loading the dependencies from external jar file, one class-loader which loads the application classes, spring-boot dev-tools will re-load the classes from second class-loader. Using this approach deployment time of the application will be reduced.
It also provides the live-reload server, it any modifications for User interfaces related files, like CSS, HTML, JS files, live-reload server will send the request to reload the browser page automatically.
7) How to prepare the spring-boot-application jar/war with all dependencies:
Spring-boot-maven-plaugin comes with spring-boot will helps in providing the fat-jar with all dependencies as executable jar file.
8) How to enable HTTP/2 support in Spring Boot:
You can enable the HTTP/2 support in Spring Boot by:
server.http2.enabled=true
9) What is the best way to expose custom application configuration with Spring Boot?
We can create a custom configuration by using annotation called @ConfigurationProperties and specify the prefix and add this annotation along with @Configuration annotation at class-level. The properties/fields specified in class, we can configure these properties along with prefix in spring-boot configuration file.
We can retrieve these values either using @Value annotation.
10) 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.
11) What is meaning of relaxed binding? And how spring boot will support?
Relaxed binding is key to the environment, where property-name does not need to exact match with configuration property name.environment property can be written in camelCase, kebab-case, snake_case, or uppercase with words separated by underscores.
12) How to write Integration tests in spring-boot?
Spring-boot-test provides the @SpringBootTest, which starts the applicationContext from classes attribute, if not it will search for all configuration classes.
13) What is Spring-boot-Actuator? What are its uses?
Spring-boot-actuator brings the spring-boot application to provide the production ready features. These features will allow us to monitor and manage the applications.
It provides the different endpoints for different purposes.
Here are the some of built-in endpoints: