Interview Questions

Spring Boot – Interview Questions

Below are some “Spring Boot interview questions”, You can start preparing for your Spring Boot interview. Go through the common interview questions and answers on Spring Boot that starts from the basic of Spring boot, talks about its features, its working, Interceptors and how to implement them. These Spring Boot interview questions and answers for experienced and freshers which will help you get hired as a Java Spring Boot Developer.

 

1. What is Spring Boot? Why should you use it?

Ans : Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.

we should use Spring Boot, because it provides lots of feature some of them are as below :

  • Very easy to develop Java-based applications Development, Unit Test and Integration Test Process.
  • To reduce Development, Unit Test and Integration Test time by providing some defaults.
  • To increase Productivity.

2. How Spring Boot is different from Spring framework?

Ans : The Spring Framework is one of the most popular application development frameworks for Java. One of the best features in Spring is that it has the Dependency Injection (DI) or Inversion Of Control (IOC), which allows us to develop loosely coupled applications.It divided into multiple modules like :

    • Spring JDBC
    • Spring MVC
    • Spring AOP
    • Spring JMS, etc

But the Questing is if Spring solves so many problems then why Spring Boot ?

So think you are using Hibernate in Spring, so in that case we have to configure DataSource, EntityManager, etc all those things and also we need to add it’s dependencies. But in case of Spring Boot :

    • Spring boot will configure all those things for us using AutoConfiguration and also it will take care of it’s internal dependencies.
    • Spring Boot provides different different Starters, developer should no need to worry about it’s dependencies and version also. Just we need to add specific Starter and it will take care of all things.

3. Can we create a non-web application in Spring Boot?

Ans : Yes by using CommandLineRunner, we can create non-web application (Standalone) also using Spring Boot.

4. Mention some advantages of Spring Boot?

Ans : There are lots of advantages of Spring Boot, some of them are :

  • Very easy and Fast Development.
  • Easy for Testing.
  • It increases Productivity.
  • It’s Autoconfigurable.
  • Very easy to integrate with other Spring Module like JDBC, MVC, etc.
  • We can develop Non web application also.
  • Spring Boot provides In-build Database Memory.
  • It has in-build Server also like Tomcat, etc. 

5. Mention the minimum requirements for a Spring boot System ?

Ans : Minimum requirement for Spring Boot System is :

  • Java
  • Build Tool – Maven / Gradle

6. How to create a Spring Boot application using Spring Initializer?

Ans : We can create Spring Boot application using multiple ways, one of them is using Spring Initializer.

For this Spring People already provided url : https://start.spring.io/ using this url we can create our Spring Boot Application. Once we open this url, we have to select Project, Language, Spring Boot version, Group, Artifact, Project Name and then Dependencies. After that when we will click on Generate, it will download .zip file with our whole structure. we can download it and use it.

7. Name the features of using Spring Boot ?

Ans : As we know, Spring Boot have lots of feature some of important features are :

  • AutoConfiguration
  • Starter POMs
  • Spring Boot CLI
  • Actuator
  • Spring Boot Initializer 

8. Explain different phases of RAD model.

9. What is RAD model?

10. What are the commands to run and stop Spring Boot executable jar file?

Ans : To run and stop Spring Boot , we can use below commands :

  • Run :
  • Stop : 

11. How can you change JDK version in Spring Boot?

Ans : We can change JDK version in Spring Boot using pom.xml. We can directly change our version as below :

      1.9

12. What is the process that you need to follow to run Spring Boot application on the custom port?

Ans : We have different process which helps us to run Spring Boot application on the custom port, these are :

  • Using application.properties file
  • Using Command Line
  • Using Embedded Server Configuration
  • Using main @SpringBootApplication Configuration

13. What is Spring Boot starter? How is it useful?

Ans : Spring Boot starters are jar dependencies, which provide a quick way to configure our application, without manually including a lot of related dependencies. In the Spring Boot Framework, all the starters follow a similar naming pattern : spring-boot-starter-*, where * denotes a particular type of application. Lots of Starter are there which is provided by Spring Boot, some of them are :

    • spring-boot-starter-web
    • spring-boot-starter-web-services
    • spring-boot-starter-thymeleaf
    • spring-boot-starter-mail
    • spring-boot-starter-data-jpa, etc
  • For example, if we want to use Spring and JPA for database access, we need to include the spring-boot-starter-data-jpa dependency in our pom.xml file
    of the project. 

14. Can you use Spring Boot with applications which are not using Spring?

15. What is auto-configuraion? How to enable or disable certain configuration?

Ans : Spring Boot auto-configuration means it will automatically configure your Spring application based on the jar dependencies that you have added.

  • For example, If HSQLDB is on your classpath, and you have not manually configured any database connection beans, then we will auto-configure
    an in-memory database.

If you find that specific auto-configure classes are being applied that you don’t want, you can use the exclude attribute of @EnableAutoConfiguration to disable them, as below :

@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}

16. What is the name of the configuration file which you can use in Spring Boot?

Ans : The configuration file which we can use is : application.properties file.

17. How to create and bootstrap a simple boot application?

18. What is DevTools in Spring Boot?

Ans : Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant. The spring-boot-dev tools module can be included in any project to provide additional development-time features. To include devtools support, simply add the module dependency to
your build as below in our pom.xml file:

org.springframework.boot
spring-boot-devtools
true

20. What are the essential components of Spring Boot?

Ans : The essential components of Spring Boot are :

  • Spring Boot Starters
  • AutoConfiguration
  • Spring Boot CLI
  • Spring Boot Actuator

21. How are properties defined? Where?

Ans: We can define properties in application.properties files as below :

22. What is spring-boot-starter-parent?

Ans : Spring Boot starters are jar dependencies, which provide a quick way to configure our application, without manually including a lot of related dependencies. In the Spring Boot Framework, all the starters follow a similar naming pattern : spring-boot-starter-*, where * denotes a particular type of application.

Lots of Starter are there which is provided by Spring Boot, one of them is “spring-boot-starter-parent”. we have to add tag, and under that we can add spring-boot-starter-parent
It provides default configurations for our applications and all the useful maven dependencies automatically.

    org.springframework.boot
spring-boot-starter-parent
2.2.2.RELEASE

23. How to enable HTTP/2 supports in Spring Boot?

24. What is a Spring Boot Actuator and what are it’s advantage ?

Ans : In Spring Boot, Actuator includes a number of additional features that help us to monitor and manage the Spring Boot application. If we want to get production-ready features in an application, we should use the Spring Boot actuator.

25. How can we create a custom endpoint in Spring Boot Actuator?

26. What is relaxed binding in Spring boot?

Ans : When we want to use some value of application.properties in our code, In that case we can use @Value annotation. But problem is both name same should match exactly.

So here Spring Boot provides feature of Relaxed Binding. For Relax Binding we have to use @ConfigurationProperties annotation in our Configuration Class. Meaning, there doesn’t need to be an exact match between the Environment property name and the bean property name. Imagine you have a bean property called allowCredentials you can use the following configuration in your properties :

  • allowCredentials: using standard camel case syntax.
  • allow-credentials: using dashed notation.
  • allow_credentials: using underscore notation.
  • ALLOW_CREDENTIALS: using upper case format.

27. What is the command to run Spring Boot application to custom port?

28. How can you access a value defined in the application? What is properties file in Spring Boot?

29. What is the primary difference between Spring and Spring Boot?

30. Explain Spring Boot Admin

31. Mention the steps to connect Spring Boot application to a database using JDBC

32. How can you connect Spring Boot to the database using JPA?

33. What are some common Spring Boot annotations?

34. What are the @RequestMapping and @RestController annotation in Spring Boot used for?

35. What are the differences between @SpringBootApplication and @EnableAutoConfiguration annotation?

36. Define the term Spring Initializer

37. Explain @RestController annotation in Spring Boot?

38. Explain Spring CLI

39. Where can you define properties in Spring Boot application?

40. What are embedded containers support by Spring

41. Explain thymeleaf in Spring Boot and how to use it ?

42. What are the Spring Boot properties?

43. What is the main difference between JPA and Hibernate?

44. Where is the database connection information specified and how does it automatically connect to H2?

45. What is the name of the default H2 database configured by Spring Boot?

46. Is it possible to replace or override the Embedded Tomcat server in Spring Boot?

47. Can you disable the default web server in the Spring Boot application?

48. How do you Add, Filter to an application? There are three methods to add filter to Spring

49. What are Spring Boot Starter Projects?

50. What is @pathVariable?

51. What is Swagger2?

52. What are different environments for enterprise application development?

53. What are the major differences between RequestMapping and GetMapping?

54. How can you define properties in Spring Boot?

55. How to create a Spring Boot project using Maven?

56. Why we use spring boot maven plugin?

57. What are the various features of Spring Boot?

58. What is the use of profiles in Spring Boot and How can you set active profile in Spring Boot??

59. What is the way to use profiles to configure the environment-specific configuration with Spring Boot?

60. How to change tomcat HTTP port?

61. What is LiveReload in Spring Boot?

62. Mention the possible sources of external configuration

63. What are the major benefits of spring Externalized Configuration?

64. What do you mean by hot-swapping in Spring Boot?

65. How to enable hot deployment and live reload on browser?

66. What is the meaning of Aspect-Oriented Programming (AOP)?

67. How to enable logging in Spring Boot?

68. you control logging with Spring Boot? How?

69. Explain overriding default properties in Spring Boot application.

70. Explain Docker in Spring Boot.

71. Define ELK stack.

72. How to handle exception in Spring Boot.

73. Explain caching.

74. What is Cross-Site Request Forgery attack?

75. Define apache freemarker.

76. What is mean by spring batch?

77. Explain Apache Kafka.

78. Explain CORS in Spring Boot?

79. Explain different types of dependency injection.

80. What are the advantages of micro service?

81. What is the default package in Spring Boot?

82. Explain the difference between an embedded container and a WAR.

83. Explain Spring MVC.

84. What is the use of tag?

85. What do you mean by aspect?

86. What is join point in Spring Boot?

87. Is excluding package without using the basePackages filter is possible? How?

88. List out benefits of using the JavaConfig method.

89. What are the steps to deploy Spring Boot web applications as JAR and WAR files?

90. Can you explain how to deploy to a different server with Spring Boot?

91. What are starter dependencies?

92. List out some of the Spring Boot Starters.

93. How to unit test and intration test a spring boot application?

94. How to enable HTTPS/SSL support in Spring boot?

95. Can you explain what happens in the background when a Spring Boot Application is “Run as Java Application”?

96. Mention the differences between JPA and Hibernate

97. What is the best way to expose custom application configuration with Spring Boot?

98. Mention the advantages of the YAML file than Properties file and the different ways to load YAML file in Spring boot

99. How is Hibernate chosen as the default implementation for JPA without any configuration?

100. What do you understand by Spring Data REST?

101. In which layer, should the boundary of a transaction start?

102. How does path=”sample”, collectionResourceRel=”sample” work with Spring Data Rest?

103. Explain how to register a custom auto-configuration.

104. How do you Configure Log4j for logging?

105. Mention the differences between WAR and embedded containers

106. How to instruct an auto-configuration to back off when a bean exists?

107. Why is Spring Data REST not recommended in real-world applications?

108. What is the error you see if H2 is not in the classpath?

109. Mention the dependencies needed to start up a JPA Application and connect to in-memory database H2 with Spring Boot?

110. Do you think, you can use jetty instead of tomcat in spring-boot-starter-web?

111. What is a shutdown in the actuator?

” As of Now that’s All I have for Spring Boot Interview Questions, These questions will help you for Interview. I am adding some more questions with answers as soon as Possible. If you have some questions which is not in this list, then you can add a comment for it and I will include here. “

Leave a Reply

avatar
  Subscribe  
Notify of