Before you go, check out these stories!

0
Hackernoon logoTop 10 Interview Questions on Spring Boot by@divyesh.aegis

Top 10 Interview Questions on Spring Boot

Author profile picture

@divyesh.aegisdivyesh.aegis

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:

  • It provides the auto-configuration feature, which load the default configuration to speed-up the Java web development company .
  • It comes with embedded web-server with different types of servers like tomcat, jetty etc.. It also provides the customizes to customize to server settings.
  • It provides the starters for different modules, by adding these start-modules, spring boot will bootstrap will the default values.
  • Spring-boot actuator is the framework, to providing API for monitoring and management of the application.
  • Spring boot provides the conditional annotations, based on which conditions which bean should be loaded.
  • Spring-boot easily integrates other modules like security, batch, and also with external frameworks like Hibernate, Redis etc.

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:

  • Application configuration: Spring boot by default will search for either application.properties file or application.yaml to read configuration in class-path root directory.
  • Command-line properties: Spring boot provides a way to pass command-line argument and convert these properties to target types using converters, and them to environment properties.
  • Profile-specific properties: As spring boot supports the profile, spring boot will recognize the configuration properties file in application-{profile}.properties, it will also load the application.properties and also application-{profile}.properties file, if nay duplicate properties are found, properties from profile will take overwrite with global properties.

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:

  • Info: display the information on the application.
  • loggers: It provides the loggers associated with different packages, we can also able to modify the loggers for each package.
  • threaddump: performs the threaddump at a particular point.
  • metrics: It shows the application metrics.
  • env: It provides the Environment properties.
  • auditevents: It exposes audit events information.
  • Health: Shows the application of health.
  • Mappings: It provides the information of all @RequestMappings specified in application.

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!