Card 03/ 06
All 6 cards
ExampleDifficulty: Intermediate1 min
A Server, Packaged Inside Your Own Jar
Running the jar this application builds into starts it listening on a real port — no separate Tomcat installation, no server to configure outside the application itself.
var context = SpringApplication.run(EmbeddedServerDemo.class, args);
var webContext = (WebServerApplicationContext) context;
int port = webContext.getWebServer().getPort();
System.out.println("Listening on port " + port + ", no server installed separately.");Listening on port 8080, no server installed separately.The older shape — a WAR file, deployed into a Tomcat or another server that already exists on the target machine — still works, and some organisations still deploy that way. What changed is that it's no longer the default or the easy path: java -jar is enough, because the server is a dependency like any other, not infrastructure you provision separately.