Top Spring Boot Interview Questions & Answers: Master Backend Development
This comprehensive guide covers essential Spring Boot concepts—including its definition, advantages, auto‑configuration, DevTools hot‑reloading, starter projects, embedded servers, Actuator monitoring, YAML configuration, MyBatis integration, WAR packaging, and common pitfalls—providing concise answers to 40+ interview‑style questions for backend developers.
1. What is Spring Boot?
Spring Boot simplifies the creation and development of Spring applications by providing opinionated defaults, embedded servers (Tomcat), automatic dependency management via starters, and the ability to run a standalone, production‑ready application with just a main method.
2. Advantages of Spring Boot
Rapid creation of independent Spring projects.
Embedded servlet container eliminates the need for WAR deployment.
Starter dependencies manage versions automatically.
Extensive auto‑configuration reduces boilerplate.
Production‑ready monitoring via Actuator.
Seamless integration with cloud platforms.
3. Reloading changes without restarting the server
Spring Boot DevTools provides automatic restart of the embedded Tomcat when classpath resources change, enabling developers to see updates instantly without manual redeployment.
4. Spring Boot vs. Spring MVC vs. Spring
Spring focuses on dependency injection (DI) and IoC. Spring MVC adds a web layer with DispatcherServlet, ModelAndView, and ViewResolver. Spring Boot builds on both, removing extensive configuration and offering starter packs.
5. What is auto‑configuration?
Spring Boot scans the classpath for spring.factories files in starters and automatically registers the necessary beans, eliminating manual configuration.
6. What is a Spring Boot starter?
A starter is a convenient dependency descriptor that aggregates required libraries for a specific technology (e.g., spring-boot-starter-data-jpa for JPA).
7. Example: Spring Boot Starter Web
Adding spring-boot-starter-web pulls in Spring MVC, Jackson, Tomcat, and logging libraries, providing a ready‑to‑use web stack.
8. Other starter project options
spring-boot-starter-web-services (SOAP)
spring-boot-starter-test (testing)
spring-boot-starter-security (authentication/authorization)
spring-boot-starter-data-jpa (JPA with Hibernate)
spring-boot-starter-data-rest (RESTful exposure of repositories)
9. What is YAML?
YAML is a human‑readable data‑serialization format often used for configuration files; it supports hierarchical data and is less error‑prone than properties files.
10. How does Spring Boot read configuration files?
By default it loads application.properties or application.yml from the classpath.
11. Integrating MyBatis with Spring Boot
Add the mybatis-spring-boot-starter dependency, annotate mapper interfaces with @Mapper, and configure the datasource in application.yml.
12. Embedded server concept
Spring Boot packages an embedded servlet container (e.g., Tomcat) inside the executable JAR, allowing the application to run like a normal Java program without external server installation.
13. Spring Boot Actuator
Actuator exposes production‑ready endpoints (health, metrics, etc.) over HTTP for monitoring and management.
14. Converting a Spring Boot JAR to a WAR
Extend SpringBootServletInitializer, set the packaging type to war in Maven, and deploy to any servlet container (Tomcat, WebLogic, etc.).
15. RequestMapping vs. GetMapping
@RequestMappingcan handle multiple HTTP methods; @GetMapping is a shortcut for @RequestMapping(method = RequestMethod.GET), improving readability.
16. When to use Spring Data REST
Ideal for rapid prototyping; it automatically exposes repository CRUD operations as RESTful endpoints, but may be unsuitable for large, production‑grade applications.
17. Core Spring Boot annotation
@SpringBootApplicationcombines @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan.
18. Enabling Jetty instead of Tomcat
Exclude the default Tomcat starter and add spring-boot-starter-jetty as a dependency.
19. Running Spring Boot
Package with Maven/Gradle and run the JAR.
Use Maven/Gradle plugins ( spring-boot:run).
Execute the main method directly from an IDE.
20. What are Spring Boot Starters?
Starters are curated dependency bundles that simplify adding a set of related libraries (e.g., web, data JPA, security) to a project.
21. Supported logging frameworks
Spring Boot supports Java Util Logging, Log4j2, and Logback; Logback is the default when using starters.
22. Hot deployment options
Spring Loaded
spring-boot-devtools
23. Adding static JavaScript resources
Place files under src/main/resources/static; they are served automatically (e.g., static/js/myapp.js).
24. Spring Data vs. Hibernate
JPA is a specification; Hibernate is a JPA implementation. Using JPA annotations keeps the code implementation‑agnostic.
25. Using an external database (MySQL example)
Add the MySQL connector dependency, remove H2, configure datasource URL, username, and password in application.properties or application.yml, then restart.
26. Selecting Hibernate as the default JPA provider
Spring Boot auto‑detects Hibernate on the classpath and configures it automatically.
27. Read‑only transactions
Mark service methods with @Transactional(readOnly = true) to hint the persistence provider that no modifications will occur, improving performance.
28. How Spring Boot starts
The main method triggers auto‑configuration; if a web application is detected, an embedded server (Tomcat/Jetty) starts automatically.
29. Changing the package name in Spring Initializr
After generating the project, edit the package declaration in the source files or use the “View full project” link to customize the base package.
30. JPA vs. Hibernate differences
JPA is a standard API; Hibernate is a concrete implementation of that API.
31. Connecting to an in‑memory H2 database
Include spring-boot-starter-web, spring-boot-starter-data-jpa, and h2 dependencies; the H2 console becomes available at /h2-console.
32. Forcing Hibernate as the JPA provider
Because Spring Boot auto‑configures Hibernate when it’s on the classpath, no extra configuration is needed.
33. Connecting to an external MySQL database
Add the MySQL driver, remove H2, configure the datasource URL, username, and password, then restart the application.
34. Using Spring Boot without an external container
The embedded Tomcat/Jetty eliminates the need for a separate servlet container.
35. How to package a WAR file
Follow the Spring guide Convert a JAR to a WAR and adjust the Maven packaging element.
36. Deploying to different servers
Build a WAR and deploy it to any Java EE server (Tomcat, WebLogic, WebSphere, etc.).
37. RequestMapping vs. GetMapping differences
@RequestMappingsupports all HTTP methods; @GetMapping is a specialized shortcut for GET requests.
38. Why Spring Data REST is not recommended for large applications
It’s great for quick prototypes but can hide complexity and limit control in production‑grade systems.
39. Core Spring Boot annotation composition
@SpringBootApplication= @SpringBootConfiguration + @EnableAutoConfiguration + @ComponentScan.
40. Enabling Spring Boot features
Inherit spring-boot-starter-parent in the POM.
Import spring-boot-dependencies BOM.
41. Does Spring Boot require an external container?
No; it ships with embedded containers like Tomcat or Jetty.
42. Ways to run a Spring Boot application
Execute the packaged JAR.
Use Maven/Gradle plugins ( spring-boot:run).
Run the main method from an IDE.
43. Understanding Spring Boot Starters
Starters are dependency bundles that provide a one‑stop solution for adding Spring modules and third‑party libraries.
44. Supported logging frameworks and default
Supports Java Util Logging, Log4j2, and Logback; Logback is the default when using starters.
45. Hot deployment methods
Spring Loaded
spring-boot-devtools
Reference: https://blog.csdn.net/Dome_/article/details/90339363
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
