Overview

Appendix A. Answers to questions

This appendix collects concise answers to the review questions from the earlier chapters, giving a quick way to check understanding of the book’s core Spring concepts. It begins with the big-picture ideas behind frameworks, Spring, and inversion of control, then moves into how Spring manages objects through the application context, beans, dependency injection, abstractions, scopes, and aspects. It also reinforces when and why to use stereotypes, configuration classes, and different injection styles so readers can distinguish between application code that Spring should manage and simpler code that should remain plain Java.

From there, the summary progresses into web development with Spring Boot and Spring MVC, covering controllers, views, request data, HTTP methods, and the difference between traditional server-rendered pages and REST-style APIs. It also explains how Spring handles request, session, and application scopes in web applications, and how to build and consume REST endpoints using JSON, response status codes, exception handling, client tools such as RestClient, WebClient, OpenFeign, and the older RestTemplate. The later chapters then shift to persistence, introducing data sources, JDBC, JdbcTemplate, transactions, Spring Data repositories, and query methods as ways to simplify database access and keep data changes safe and consistent.

The appendix finishes by emphasizing testing and reliability, showing how unit tests, mocks, and happy-path and exception-path scenarios help ensure behavior remains correct as applications evolve. Overall, the answers reinforce a practical Spring mindset: use the framework where it adds value, keep components loosely coupled, choose the right scope and data access approach for the problem, and rely on Spring’s built-in features to reduce boilerplate while improving maintainability and safety.

A.16 Chapter 16 – Implementing integration tests for Spring apps

  1. What is an integration test?: An integration test checks how multiple parts of an application work together. It does not focus only on one method or one class, but on the collaboration between components.
  2. What is a Spring integration test?: A Spring integration test checks how your code works together with features provided by Spring. For example, it can verify dependency injection, configuration, transactions, persistence, security, or other Spring-managed behavior.
  3. Does an integration test always need to mock all dependencies?: No, an integration test does not always need to mock all dependencies. If the purpose of the test is to check how two real components interact, you can let those real components work together.
  4. What does the @SpringBootTest annotation do?: The @SpringBootTest annotation tells Spring Boot to start the application context for the test. This allows Spring to create and manage the beans as it does when the application runs.
  5. What is the purpose of @MockitoBean?: The @MockitoBean annotation creates a mock object and adds it to the Spring context. We use it when we want Spring to inject a mock instead of the real bean.
  6. What is a controller integration test?: A controller integration test checks how the application exposes functionality through web endpoints. It sends a request to an endpoint and validates the response.
  7. What is MockMvc?: MockMvc is a Spring testing tool used to call Spring MVC endpoints from a test. It lets us test controllers without starting a real HTTP server.
  8. How are unit tests, Spring integration tests, and controller integration tests different?: Unit tests check isolated logic and are usually fast. Spring integration tests check how the app works with Spring features, while controller integration tests check how clients interact with the app through HTTP endpoints.

FAQ

What is Spring framework used for?Spring is a popular Java framework used to build many kinds of applications, especially backend applications.
What is a bean in Spring?A bean is an object instance that has been added to the Spring context. Once it is in the context, Spring can manage it.
What does dependency injection mean?Dependency injection means the framework gives an object the dependencies it needs instead of the object creating them.
Why is constructor injection preferred?Constructor injection is preferred because it is clearer, safer, and easier to test.
What is the default bean scope in Spring?The default bean scope in Spring is singleton.
What is an aspect in Spring AOP?An aspect is a piece of logic that Spring executes when specific methods are called.
What does @RestController do?@RestController combines @Controller and @ResponseBody, so methods return data directly in the HTTP response.
What is the role of JdbcTemplate?JdbcTemplate is a Spring tool that makes working with a database easier when using JDBC. It helps you write less code for common operations, such as adding or reading records.
What does @Transactional do?The @Transactional annotation tells Spring to wrap a method call in a transaction.
What is a unit test?A unit test checks a small piece of logic in isolation. It focuses on one method, class, or small component without using the real dependencies around it.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Spring Start Here, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Spring Start Here, Second Edition ebook for free