Spring Boot Interview Questions
Spring Boot is a core topic in Java backend and full-stack interviews, from junior to senior. These are the questions interviewers actually ask, with concise answers you can speak confidently.
17 questions with concise, interview-ready answers.
1. What is Spring Boot, and how is it different from the Spring Framework?
Spring Boot is a framework built on top of the Spring Framework that makes it fast to create stand-alone, production-ready Spring applications with minimal configuration. The classic Spring Framework is powerful but requires a lot of manual setup — defining beans, configuring XML or Java config, and wiring up a server. Spring Boot adds auto-configuration, starter dependencies, an embedded server, and sensible defaults so you can run an app with almost no boilerplate. In short, Spring is the foundation and Spring Boot is an opinionated layer that removes the setup friction.
2. What is auto-configuration in Spring Boot?
Auto-configuration automatically configures your application based on the dependencies on the classpath and the properties you have set. For example, if Spring Boot sees a database driver and Spring Data JPA on the classpath, it configures a DataSource and an EntityManager for you. It works through conditional annotations like @ConditionalOnClass and @ConditionalOnMissingBean, so it only applies a configuration when it makes sense and backs off when you define your own. This is why a Spring Boot app works out of the box with very little code.
3. What are Spring Boot starters?
Starters are curated sets of dependencies you add to your build to pull in everything needed for a particular feature, with compatible versions managed for you. For example, spring-boot-starter-web brings in Spring MVC, Jackson for JSON, and an embedded Tomcat server in one dependency. They save you from hunting down individual libraries and resolving version conflicts. Common ones include starter-web, starter-data-jpa, starter-security, and starter-test.
4. What does the @SpringBootApplication annotation do?
It is a convenience annotation that combines three others: @Configuration, which marks the class as a source of bean definitions; @EnableAutoConfiguration, which turns on Spring Boot auto-configuration; and @ComponentScan, which scans the current package and its sub-packages for components. You put it on your main class, which also has the main method that calls SpringApplication.run. It is essentially the entry point that bootstraps the whole application.
5. What is dependency injection and inversion of control in Spring?
Inversion of control means the framework, not your code, is responsible for creating objects and managing their lifecycle. Dependency injection is the technique Spring uses to achieve this: instead of a class creating its own dependencies, Spring provides them from the application context. This produces loosely coupled, more testable code because you can swap implementations without changing the dependent class. The Spring IoC container holds and wires these objects, which are called beans.
6. What is the Spring IoC container and what is a bean?
The IoC container is the part of Spring that creates, configures, and manages objects and their dependencies, typically represented by the ApplicationContext. A bean is simply an object that the container manages — created from your configuration or component-scanned classes. The container reads bean definitions, instantiates them, injects their dependencies, and controls their lifecycle. By default beans are singletons, meaning one shared instance per container.
7. What is the difference between @RestController and @Controller?
@Controller is the classic Spring MVC annotation for a web controller whose methods usually return a view name, which a template engine then renders to HTML. @RestController is a convenience annotation that combines @Controller and @ResponseBody, so every method returns data written directly to the HTTP response body, typically serialized to JSON. You use @RestController for REST APIs and @Controller for server-rendered web pages. With plain @Controller you would add @ResponseBody yourself to return raw data.
8. What does @Autowired do, and what are the ways to inject dependencies?
@Autowired tells Spring to inject a matching bean from the container automatically, by type. There are three injection styles: constructor injection, where dependencies are passed through the constructor; setter injection; and field injection directly on the field. Constructor injection is generally preferred because it makes dependencies explicit, supports immutability, and is easy to test. Note that with a single constructor, modern Spring injects its parameters automatically, so @Autowired is often optional there.
9. What are @Component, @Service, and @Repository, and how do they differ?
All three are stereotype annotations that register a class as a Spring-managed bean, picked up by component scanning. @Component is the generic stereotype, while @Service and @Repository are specializations that express intent. @Service marks a class holding business logic, and @Repository marks a data-access class and adds automatic translation of persistence exceptions into Spring's DataAccessException hierarchy. Functionally they are similar, but using the specific ones improves readability and, for @Repository, adds the exception handling benefit.
10. How do application.properties and application.yml work?
They are the externalized configuration files where you set properties like the server port, database URL, and logging levels, so you can change behavior without touching code. The .properties format uses simple key=value pairs, while the .yml format uses indented, hierarchical YAML, which is more readable for nested settings. Spring Boot loads them automatically from standard locations such as the classpath or a config folder. You can also override these values with environment variables or command-line arguments.
11. What are Spring Boot profiles?
Profiles let you define different configurations for different environments, such as dev, test, and production. You put environment-specific settings in files like application-dev.properties and activate a profile with the spring.profiles.active property. You can also annotate beans with @Profile so they are only created when a given profile is active. This makes it easy to switch database connections, logging, and feature toggles between environments without code changes.
12. What is Spring Boot Actuator?
Actuator adds production-ready features for monitoring and managing your application through built-in endpoints. It exposes information such as health checks, metrics, environment properties, and bean details, usually under the /actuator path. Common endpoints include /actuator/health and /actuator/metrics, and you control which endpoints are exposed through configuration. It is widely used with monitoring tools and load balancers to check whether the app is up and healthy.
13. What is an embedded server in Spring Boot?
Spring Boot ships with an embedded web server — Tomcat by default — bundled inside the application itself, so you do not need to install or deploy to an external server. You can build the app as an executable JAR and run it with java -jar, and it starts its own server on a configured port. This simplifies deployment and is a natural fit for containers and microservices. You can swap Tomcat for Jetty or Undertow by changing the starter dependency.
14. How do you handle exceptions in a Spring Boot REST API?
The standard approach is centralized exception handling with @ControllerAdvice or @RestControllerAdvice combined with @ExceptionHandler methods. A class annotated with @RestControllerAdvice catches exceptions thrown across all controllers and lets you return a consistent error response and HTTP status. You can also use @ExceptionHandler inside a single controller for local handling, or throw a ResponseStatusException to set a status directly. This keeps error handling clean and avoids repeating try-catch logic in every endpoint.
15. What is Spring Data JPA, and what does a repository interface give you?
Spring Data JPA is a layer on top of JPA and Hibernate that drastically reduces the boilerplate of writing data-access code. You define a repository as an interface extending something like JpaRepository or CrudRepository, and Spring generates the implementation at runtime. You immediately get methods such as save, findById, findAll, and delete without writing any SQL. You can also add custom queries by following method-name conventions like findByEmail, or by writing JPQL with the @Query annotation.
16. What is the difference between JPA and Hibernate?
JPA (Jakarta Persistence API, formerly Java Persistence API) is a specification that defines a standard way to map Java objects to database tables and manage persistence. Hibernate is the most popular implementation of that specification — the actual library that does the work. By coding against the JPA interfaces, you keep your code portable and could in principle swap the provider. In a typical Spring Boot app, Spring Data JPA is the abstraction, JPA is the standard, and Hibernate is the default engine underneath.
17. What are the common HTTP method mapping annotations in Spring Boot?
Spring provides @RequestMapping plus shortcut annotations for each HTTP verb: @GetMapping for reads, @PostMapping for creates, @PutMapping for full updates, @PatchMapping for partial updates, and @DeleteMapping for deletes. You also use @PathVariable to bind values from the URL path, @RequestParam for query parameters, and @RequestBody to deserialize the request body into an object. Together these let you build clean RESTful endpoints that map directly to resources and actions.
Get these answered live in your real interview
NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.
Try NostrobeAI free