---
title: "Spring Boot: Java Application Framework Essentials"
description: "Test your knowledge of Spring Boot covering dependency injection, auto-configuration, REST controllers, Spring Data, and production-ready features."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/spring-boot-fundamentals-quiz
---

# Spring Boot: Java Application Framework Essentials

Spring Boot removed most of the ceremony from Java backend development, but the framework still does a lot of work you cannot see. This quiz walks through dependency injection, auto-configuration, REST controllers, Spring Data JPA, configuration and profiles, security basics, Actuator, and testing. Answer each question and read the explanations to sharpen your mental model of what Spring is really doing under the hood.

## Questions

### 1. What core principle lets the Spring container create and wire your objects instead of you calling `new` yourself?

- Inversion of Control, where the container owns object creation and wiring.
- Reflection, because Spring reads annotations at runtime.
- Aspect-oriented programming, because it intercepts method calls.
- Lazy initialization, because beans are created on demand.

**Hint:** The container is in charge, not your constructor calls.

### 2. Which injection style does the Spring team recommend for required dependencies?

- Field injection with `@Autowired` on the private field.
- Setter injection so dependencies can change at runtime.
- Constructor injection, which makes dependencies explicit and final.
- Static injection through a shared singleton holder.

**Hint:** Which style lets you mark the dependency `final`?

### 3. What is the default scope of a Spring bean?

- Prototype, so a new instance is created on every injection.
- Singleton, one shared instance per application context.
- Request, one instance per HTTP request.
- Thread, one instance per thread.

**Hint:** Think "one per context" unless you say otherwise.

### 4. When two beans of the same type exist, how do you tell Spring which one to inject?

- Mark one with `@Qualifier` (or `@Primary`) to disambiguate.
- Rename the injection field to match one bean name automatically.
- Delete one of the beans so only one candidate remains.
- Spring picks one at random and logs a warning.

**Hint:** One annotation names the bean, another marks the default.

### 5. What three annotations does `@SpringBootApplication` combine?

- `@Configuration`, `@EnableAutoConfiguration`, and `@ComponentScan`.
- `@Controller`, `@Service`, and `@Repository`.
- `@RestController`, `@RequestMapping`, and `@Bean`.
- `@EnableWebMvc`, `@EnableJpaRepositories`, and `@Import`.

**Hint:** It configures beans, enables auto-config, and scans for components.

### 6. How does Spring Boot auto-configuration decide whether to configure a feature?

- It runs everything and disables what fails at startup.
- It uses conditional annotations like `@ConditionalOnClass` and `@ConditionalOnMissingBean`.
- It reads a mandatory `autoconfig.xml` file you must provide.
- It asks the developer interactively on first run.

**Hint:** It reacts to what is on the classpath and which beans you have not defined.

### 7. What is the main purpose of a Spring Boot "starter" dependency?

- It generates boilerplate controller code for you.
- It is a curated set of dependencies for a capability, versioned together.
- It replaces the need for a build tool like Maven or Gradle.
- It is a runtime agent that profiles your application.

**Hint:** Think one dependency that pulls in a coherent, compatible bundle.

### 8. How does `@RestController` differ from `@Controller`?

- It adds `@ResponseBody` semantics so return values are serialized to the response body.
- It only works with WebFlux, not Spring MVC.
- It automatically secures every endpoint it declares.
- It disables JSON serialization in favor of plain text.

**Hint:** One returns view names, the other returns serialized data.

### 9. Which annotation binds a JSON request body to a method parameter?

- `@PathVariable`, because it maps URI segments.
- `@RequestParam`, because it reads query parameters.
- `@RequestBody`, which deserializes the body into the parameter type.
- `@ModelAttribute`, because it always builds the object from the body.

**Hint:** You want the whole payload, not a path segment or query param.

### 10. Which annotation is the shortcut for handling HTTP GET requests on a path?

- `@GetMapping`, a specialization of `@RequestMapping` for GET.
- `@RequestMapping(method = POST)` with a GET flag.
- `@HttpGet`, the standard Servlet annotation.
- `@Query`, which maps read-only endpoints.

**Hint:** It has a matching sibling for POST, PUT, and DELETE.

### 11. What does `ResponseEntity` let a controller method control that a plain return type cannot?

- The database transaction boundary for the request.
- The HTTP status code, headers, and body together.
- The bean scope of the controller.
- The order in which filters run.

**Hint:** Think status plus headers plus body in a single object.

### 12. What do you get by extending `JpaRepository<User, Long>`?

- A generated proxy providing CRUD and pagination methods without an implementation.
- An abstract class you must subclass and implement manually.
- A raw JDBC connection you manage yourself.
- A REST endpoint automatically for every entity.

**Hint:** You declare an interface and never write the implementation.

### 13. How does Spring Data derive a query from a method named `findByEmailAndActiveTrue`?

- It parses the method name into a query at startup using property and keyword conventions.
- It requires a matching stored procedure in the database.
- It executes the method name as literal SQL text.
- It always needs an explicit `@Query` annotation to work.

**Hint:** The method name itself is the specification.

### 14. What problem does the N+1 select issue describe in JPA?

- A query returns one extra row beyond what was requested.
- One query for the parents plus one additional query per parent to load a relation.
- A deadlock between N transactions competing for one row.
- A cache miss that forces N retries of the same query.

**Hint:** Count the queries: one for the list, then one per item.

### 15. Where should `@Transactional` typically be applied in a layered Spring Boot app?

- On the service-layer method that groups the related repository calls.
- On every repository method individually.
- On the controller method handling the request.
- On the main application class.

**Hint:** Think business unit of work, not a single query.

### 16. What does a Spring profile let you do?

- Activate different beans and property values per environment.
- Profile CPU usage of your beans at runtime.
- Encrypt the application properties file.
- Restrict which users can call an endpoint.

**Hint:** Think dev vs test vs prod for the same jar.

### 17. Which annotation injects a single property value into a field?

- `@Value("${app.timeout}")` on the field or constructor parameter.
- `@ConfigurationProperties` on the field.
- `@Autowired` with the property name.
- `@Bean` on a getter returning the value.

**Hint:** It uses a `${...}` placeholder for one value.

### 18. What advantage does `@ConfigurationProperties` offer over scattered `@Value` fields?

- Type-safe binding of a whole group of related properties into one object.
- It disables externalized configuration entirely.
- It forces all properties to be constants at compile time.
- It removes the need for any properties file.

**Hint:** Think one class holding a whole related group of settings.

### 19. What triggers bean validation on an incoming request body in a controller?

- Adding `@Valid` (or `@Validated`) before the `@RequestBody` parameter.
- Annotating the controller class with `@Validated` only.
- Nothing; Spring validates every request body automatically.
- Declaring the DTO fields as `final`.

**Hint:** One annotation right before the request-body parameter.

### 20. What is the role of `@ControllerAdvice` (or `@RestControllerAdvice`)?

- To centralize exception handling and response shaping across many controllers.
- To advise the container on bean creation order.
- To cache controller responses automatically.
- To generate OpenAPI documentation for controllers.

**Hint:** Think one class that handles exceptions for all controllers.

### 21. In Spring Security, what is the difference between authentication and authorization?

- Authentication verifies identity; authorization decides what that identity may access.
- Authentication checks permissions; authorization logs the user in.
- They are two names for the same login step.
- Authentication encrypts traffic; authorization compresses it.

**Hint:** Identity first, then permissions.

### 22. How is HTTP security most commonly configured in modern Spring Boot?

- By declaring a `SecurityFilterChain` bean that customizes the `HttpSecurity`.
- By editing an XML `security-config.xml` file.
- By annotating the main class with `@Secure`.
- By setting a single property `security.enabled=true`.

**Hint:** It is a bean, not the old adapter subclass.

### 23. What does Spring Boot Actuator provide?

- Production-ready endpoints for health, metrics, and application info.
- A code generator that scaffolds controllers.
- A replacement for your logging framework.
- An embedded database for testing.

**Hint:** Think health checks and metrics out of the box.

### 24. Which Actuator endpoint is typically wired to a load balancer or orchestrator readiness probe?

- `/actuator/health`, which reports application and dependency status.
- `/actuator/beans`, which lists every bean.
- `/actuator/env`, which dumps configuration properties.
- `/actuator/mappings`, which lists request mappings.

**Hint:** Which endpoint says "am I up and ready?"

### 25. What does `@SpringBootTest` do that a plain unit test does not?

- It loads a full application context so beans are wired as in production.
- It mocks every bean automatically so nothing real runs.
- It disables the database for all tests.
- It only compiles the test without executing it.

**Hint:** It boots the whole context, not a single class in isolation.

### 26. When would you use a slice test like `@WebMvcTest` instead of `@SpringBootTest`?

- To load only the web layer for a controller, keeping the test fast and focused.
- To run the test against the real production database.
- To disable dependency injection completely.
- To test only static utility methods.

**Hint:** Load only the layer under test, not the whole app.

### 27. What does `@MockBean` do inside a Spring Boot test?

- It replaces a bean in the context with a Mockito mock.
- It permanently deletes the bean from the application.
- It generates a new real implementation of the bean.
- It marks the bean as lazy in production.

**Hint:** Think Mockito mock, swapped into the context.
