Spring Boot: Java Application Framework Essentials
Spring Boot: Java Application Framework Essentials
Test your knowledge up to 20 randomized questions
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.
Answer key and explanations27 questions
The quiz above draws 20 questions at random from these 27, so a second attempt will not be the same run. Everything in the pool is listed here.
What core principle lets the Spring container create and wire your objects instead of you calling `new` yourself?
AnswerInversion of Control, where the container owns object creation and wiring.
Inversion of Control means the framework, not your code, decides when and how collaborators are created and injected.
Which injection style does the Spring team recommend for required dependencies?
AnswerConstructor injection, which makes dependencies explicit and final.
Constructor injection produces fully initialized, immutable beans and is trivial to instantiate in unit tests.
What is the default scope of a Spring bean?
AnswerSingleton, one shared instance per application context.
Singleton scope is the default; the same bean instance is shared across the whole context.
When two beans of the same type exist, how do you tell Spring which one to inject?
AnswerMark one with `@Qualifier` (or `@Primary`) to disambiguate.
Use `@Qualifier` to select a specific bean by name, or `@Primary` to declare the default candidate.
What three annotations does `@SpringBootApplication` combine?
Answer`@Configuration`, `@EnableAutoConfiguration`, and `@ComponentScan`.
`@SpringBootApplication` merges `@Configuration`, `@EnableAutoConfiguration`, and `@ComponentScan` into one annotation.
How does Spring Boot auto-configuration decide whether to configure a feature?
AnswerIt uses conditional annotations like `@ConditionalOnClass` and `@ConditionalOnMissingBean`.
Auto-configuration classes are gated by `@Conditional` checks on classpath contents, properties, and existing beans.
What is the main purpose of a Spring Boot "starter" dependency?
AnswerIt is a curated set of dependencies for a capability, versioned together.
Starters group the libraries needed for a feature into a single, version-aligned dependency.
How does `@RestController` differ from `@Controller`?
AnswerIt adds `@ResponseBody` semantics so return values are serialized to the response body.
`@RestController` combines `@Controller` and `@ResponseBody`, writing return values straight to the HTTP body.
Which annotation binds a JSON request body to a method parameter?
Answer`@RequestBody`, which deserializes the body into the parameter type.
`@RequestBody` triggers HTTP message conversion, turning the request payload into a Java object.
Which annotation is the shortcut for handling HTTP GET requests on a path?
Answer`@GetMapping`, a specialization of `@RequestMapping` for GET.
`@GetMapping`, along with `@PostMapping`, `@PutMapping`, and `@DeleteMapping`, are HTTP-method shortcuts for `@RequestMapping`.
What does `ResponseEntity` let a controller method control that a plain return type cannot?
AnswerThe HTTP status code, headers, and body together.
`ResponseEntity<T>` gives explicit control of status code, headers, and body in one return value.
What do you get by extending `JpaRepository<User, Long>`?
AnswerA generated proxy providing CRUD and pagination methods without an implementation.
Extending a Spring Data repository interface yields a generated proxy with CRUD, sorting, and paging support.
How does Spring Data derive a query from a method named `findByEmailAndActiveTrue`?
AnswerIt parses the method name into a query at startup using property and keyword conventions.
Query derivation parses the method name against entity properties and keywords to generate the query.
What problem does the N+1 select issue describe in JPA?
AnswerOne query for the parents plus one additional query per parent to load a relation.
N+1 happens when loading a collection lazily issues one query per parent; a fetch join or entity graph fixes it.
Where should `@Transactional` typically be applied in a layered Spring Boot app?
AnswerOn the service-layer method that groups the related repository calls.
Place `@Transactional` on service methods so a whole business operation commits or rolls back together.
What does a Spring profile let you do?
AnswerActivate different beans and property values per environment.
Profiles group beans and property files so a single build behaves differently per environment.
Which annotation injects a single property value into a field?
Answer`@Value("${app.timeout}")` on the field or constructor parameter.
`@Value` with a `${...}` placeholder injects one resolved property; use `@ConfigurationProperties` for grouped, type-safe binding.
What advantage does `@ConfigurationProperties` offer over scattered `@Value` fields?
AnswerType-safe binding of a whole group of related properties into one object.
`@ConfigurationProperties` binds a prefixed group of settings into a strongly typed, validatable object.
What triggers bean validation on an incoming request body in a controller?
AnswerAdding `@Valid` (or `@Validated`) before the `@RequestBody` parameter.
Mark the `@RequestBody` parameter with `@Valid` so its Jakarta Validation constraints are checked before the handler executes.
What is the role of `@ControllerAdvice` (or `@RestControllerAdvice`)?
AnswerTo centralize exception handling and response shaping across many controllers.
`@ControllerAdvice` groups cross-cutting handler logic, most commonly global `@ExceptionHandler` methods, in one place.
In Spring Security, what is the difference between authentication and authorization?
AnswerAuthentication verifies identity; authorization decides what that identity may access.
Authentication answers "who are you?" and authorization answers "what are you allowed to do?".
How is HTTP security most commonly configured in modern Spring Boot?
AnswerBy declaring a `SecurityFilterChain` bean that customizes the `HttpSecurity`.
Modern Spring Security is configured with a `SecurityFilterChain` bean using the lambda `HttpSecurity` DSL.
What does Spring Boot Actuator provide?
AnswerProduction-ready endpoints for health, metrics, and application info.
Actuator adds ready-made monitoring and management endpoints for running applications.
Which Actuator endpoint is typically wired to a load balancer or orchestrator readiness probe?
Answer`/actuator/health`, which reports application and dependency status.
The health endpoint, with its liveness and readiness groups, is the standard target for orchestration probes.
What does `@SpringBootTest` do that a plain unit test does not?
AnswerIt loads a full application context so beans are wired as in production.
`@SpringBootTest` starts the Spring context so components collaborate as they would at runtime.
When would you use a slice test like `@WebMvcTest` instead of `@SpringBootTest`?
AnswerTo load only the web layer for a controller, keeping the test fast and focused.
`@WebMvcTest` boots just the web slice with `MockMvc`, so controller tests stay fast and isolated from lower layers.
What does `@MockBean` do inside a Spring Boot test?
AnswerIt replaces a bean in the context with a Mockito mock.
`@MockBean` adds or replaces a bean in the test context with a Mockito mock you can program and verify.





