Lean Servlet Web Applications
Lean Servlet applications are Java Web Applications that are built without using Web Application Framework, but instead are just a collection of Servlets, Filters, JSPs and Java classes.
Lean Servlet Applications:
- Are highly modular.
- Have a source hierarchy that is easy to understand and navigate.
- Are packaged by functionality not by layer.
- Have the minimum number of third party dependencies.
- Are built directly on top of the Servlet API. For instance, they implement their own Servlets and do not rely on a Controller Servlet to handle all incoming requests, or any intermediate Filters to wrap or preprocess the Request.
- Are designed to make it fast to build out more functionality (even things that had never been previously envisaged)
- Behave predictably and fail loudly.
- Are fast to build and deploy, and perform well.
- Are not obsessed with being REST-ful, but like to keep their URLs logical and readable. They do not abuse the HTTP GET method.
Rules for developing Lean Servlet Applications:
- No pages in the application link directly to JSPs, always to a Servlet which forwards to the JSP.
- All application-wide Filters and Servlets such as error handlers are defined explicitly in web.xml.
- Business/functional Servlets are not defined in web.xml but are mapped using Servlet 3.0 annotations.
- Any shared or generally useful jar dependencies should be moved to the container's lib directory in order to keep the application WAR files as lightweight as possible. If this is too difficult to manage with Maven (or other prescriptive build tool), then don't use it.
- Exceptions should be handled by the container, not by each individual Servlet.
Lean Servlets is a concept that is being developed by Simon Kelly. Please message @si-kelly on twitter if you have suggestions, comments or you want to know more.