Adding portfolio components using Spring Boot starters
Remember in the previous section how we talked about adding H2? Or Spring MVC? Maybe Spring Security?
I’m going out on a limb here, but I’m presuming you don’t have any project dependency coordinates committed to memory. What does Spring Boot offer? A collection of virtual dependencies that will ease adding things to the build.
If you add org.springframework.boot:spring-boot-starter-web
(as shown here) to the project, it will activate Spring MVC:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
If you add org.springframework.boot:spring-boot-starter-data-jpa
to the project (as shown here), it will activate Spring Data JPA:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
There are 50 different Spring Boot starters, each with the perfect coordinates to various bits of the Spring portfolio and other related third-party libraries.
But the problem isn’t just a shortcut to adding Spring MVC to classpath
. There’s little difference between org.springframework.boot:spring-boot-starter-web
and org.springframework:spring-webmvc
. That’s something we probably could have figured out with our favorite internet search engine.
No, the issue is that if we want Spring MVC, it implies we probably want the whole Spring Web experience.
Note
Spring MVC versus Spring Web? Spring Framework has three artifacts involving web applications: Spring Web, Spring MVC, and Spring WebFlux. Spring MVC is servlet-specific bits. Spring WebFlux is for reactive web app development and is not tied to any servlet-based contracts. Spring Web contains common elements shared between Spring MVC and Spring WebFlux. This mostly includes the annotation-based programming model Spring MVC has had for years. This means that the day you want to start writing reactive web apps, you don’t have to learn a whole new paradigm to build web controllers.
If we added spring-boot-starter-web
, this is what we’d need:
- Spring MVC and the associated annotations found in Spring Web. These are the Spring Framework bits that support servlet-based web apps.
- Jackson Databind for serialization and deserialization (including JSR 310 support) to and from JSON.
- An embedded Apache Tomcat servlet container.
- Core Spring Boot starter.
- Spring Boot.
- Spring Boot Autoconfiguration.
- Spring Boot Logging.
- Jakarta annotations.
- Spring Framework Core.
- SnakeYAML to handle YAML Ain’t Markup Language (YAML)-based property files.
Note
What is Jakarta? Jakarta EE is the new official specification, replacing Java EE. Oracle wouldn’t relinquish its trademarked Java brand (nor grant a license) when it released its Java EE specs to the Eclipse Foundation. So, the Java community chose Jakarta as the new brand going forward. Jakarta EE 9+ is the official version that Spring Boot 3.0 supports. For more details, checkout my video What is Jakarta EE? at https://springbootlearning.com/jakarta-ee
This starter will bring in enough for you to build a real web application, not counting a templating engine. Now, we have autoconfiguration, which registers key beans in the application context. And we also have starters that simplify putting Spring portfolio components in classpath
. But what’s missing is our ability to plug in customized settings, which we’ll tackle in the next section.