Card 05/ 06
Practice: Reading a pom.xml for an Embedded Server
Two starters and no server declared: will java -jar start one, and which?
Whether a Boot application starts a web server depends on the starters in its pom.xml, not on any server you declare. Read the setup below and decide, with a reason, before opening the answer.
A pom.xml declares spring-boot-starter-web, spring-boot-starter-data-jpa, and nothing else related to a server. Will java -jar on the built jar start something listening on a port? If so, what is doing the listening, and on which port?
See the answer
Yes. spring-boot-starter-web brings in spring-boot-starter-tomcat, so an embedded Tomcat is on the classpath and auto-configuration, which creates beans for what it finds on the classpath, starts it on port 8080. spring-boot-starter-data-jpa adds database access, not a server, and does not change this. The port is 8080 unless server.port says otherwise, so running it on 9090 without editing anything takes --server.port=9090 on the command line.
The same reasoning answers the reverse question: a project with only spring-boot-starter-data-jpa starts no web server at all, because nothing brings one onto the classpath.
← → move through sections and cards