Swipe to navigate through the chapters of this book
Spring can certainly be used in a standalone environment, but the most common environment for Spring has historically been in an enterprise environment, powering web applications and backend services in a managed server. This chapter will demonstrate some aspects of integration in a Jakarta EE container (formerly known as Java EE, or J2EE, or maybe even just "Tomcat" depending on your level of exposure, currency, and experience).
Please log in to get access to this content
Java has always had confusion around names and versions: for example, there used to be a release called J2SE 4, which was “Java 2, Standard Edition,” version 1.4. The 1.4 edition was also edition 4… and most people without a lot of exposure to Java spent a lot of time wondering what versions referred to what components. This was something that plagued Sun, the company that created Java, and has never really gone away.
Wait, there’s the word “context” again. Spring application contexts aren’t quite the same as Jakarta EE application contexts, but they’re similar; they just don’t have the same roles at all. Remember, we warned you that this could get interesting.
There are multiple HTTP specifications, because HTTP can do a lot and in a lot of different ways. A useful reference for the “basic HTTP specification” as everyone thinks of it is HTTP 1.1: see https://tools.ietf.org/html/rfc2616 – but note that that’s definitely not the final word on HTTP.
Servlet has a service(ServletRequest, ServletResponse); HttpServlet overrides this method to delegate to a service(HttpServletRequest, HttpServletResponse) method, which – if not overridden itself – will delegate to doGet(), doPost(), and so forth.
They will not, however, survive this chapter. They’re written with manual servlet processes in mind, which is what programmers used to have to do back before Facebook was a thing. Spring has a better way; we’ll see what that is in Chapter 6. In the meantime, these servlets will help us validate what we’re learning in this chapter. With that said, we’re going to be writing equivalents over and over again.
The management of transitive dependencies is one of the things that make build tools in Java like Maven or Gradle so absolutely necessary. Without transitive dependencies, programmers would have to chase down the entire dependency tree for every library they used. The transitive dependency mechanism built into the tools is far, far, far better.
So now, if anyone ever asks you what war is good for, you can tell them with a straight face that wars are good for deploying web applications built in Java. Everyone wins, but be careful: this might get a cup of coffee thrown at you.
Jtwig, found at https://Jtwig.org/ , bills itself as a “modern template engine for Java.” For our purposes, it’s handy because it’s simple to bootstrap. As our chapter continues and we build services rather than a user interface, Jtwig will become less important for us.
We’ve already shown two Servlets, but they don’t run properly – because we haven’t shown how to populate the Servlet context with a Spring context yet. The Servlet here is a “hello, world” servlet, something to make sure our project is working properly. Once we know that we’re able to run a servlet container and interact with it, we’ll have validated our process and we won’t need to go back over it – only replicate it.
It’s “bated” breath and not “baited,” no matter how much your authors wanted to seem as if they’d been eating fish.
Curl can be found at https://curl.haxx.se/ – if it’s not already installed on your OS, convenient downloads can be found at that site.
We’ll be introducing @Controller and other such annotations in Chapter 6.
It actually scans entire package trees – so any packages that have the scanned packages as their roots will be scanned as well. We could also use the Java configuration approach, and not scan at all; see Chapter 3 for how to do this.
This means that it takes a variable number of arguments. In the method declaration, this is often shown by using something like “String … args”, where args is actually a typed array.
So many contexts!
It’s “incredibly useful,” so to speak: Chapter 6 will show us how to get around pretty much all of this. But this is basically what’s happening behind the scenes.
- Spring and Jakarta EE
Joseph B. Ottinger
- Sequence number
- Chapter number
- Chapter 5