When I started learning Spring, I noticed something about many of the tutorials I found.
They often showed how to use a feature, but not always why it worked or when you should choose one approach over another.
I learn best by building things and documenting what I discover, so I started a project called spring-by-example.
The idea is simple: instead of building one large application, Iโm creating a collection of small, focused examples where each example explores a specific Spring concept with clear explanations, tests, and documentation.
Iโm happy to say that Iโve now completed Module 10 โ Spring Web (Spring MVC). ๐
The module covers:
- DispatcherServlet
- Controllers
- Request Mapping
- Path Variables
- Request Parameters
- Request Body
- Response Body
- Model and View
- View Resolvers
- Exception Handling
- Request Scope
- Session Scope
- Application Scope
One of the things I enjoyed about this module was understanding what actually happens when an HTTP request enters a Spring MVC application.
The DispatcherServlet acts as the front controller, receiving incoming requests and coordinating the request-handling process. Controllers then define how those requests should be handled using mappings such as @GetMapping and @PostMapping.
I also explored different ways of working with request data, including path variables, request parameters, and request bodies, as well as how Spring converts incoming data into Java objects.
The view-related examples helped connect the pieces between a controller, a model, and a view. ModelAndView can be used to return both model data and a logical view name, while ViewResolver determines which actual view should be rendered.
Exception handling was another important part of the module. Using mechanisms such as @ExceptionHandler and @ControllerAdvice, it becomes possible to keep error-handling logic organized instead of putting it directly into every controller.
Finally, I explored Spring's web scopes - request, session, and application scope โ and how the lifetime of a bean can be tied to the lifecycle of an HTTP request, user session, or web application.
The goal isnโt just to collect Spring annotations and APIs. Iโm trying to understand how Spring works under the hood, how its features fit together, and why these features exist, one concept at a time.
The project is open source, and Iโm continuing to build it as I learn:
๐ GitHub: https://gith.ub/dsAQrAU5
๐ GitLab: https://gitl.ab/gfDEyGH3
Thereโs still a long way to go, but completing another module feels like a good milestone. ๐
Next up: Module 11 - Testing - exploring how to test Spring applications, starting with unit testing and the Spring TestContext, followed by @SpringBootTest, @MockBean, @TestConfiguration, and integration testing.
If youโve worked with Spring MVC before, whatโs one part of the request-handling process you think developers commonly misunderstand?
Top comments (0)