Take a look at the default dependencies included in Spring Boot for web.
- [Instructor] Before we get started building web applications with Spring Boot, I wanna talk a little bit about what comes with a web starter. And web applications are by far the most common places to start with Spring Boot so we're gonna use this as an example of what comes with a traditional starter. Now, in the Spring world and especially with Spring Boot, there's no difference between a traditional HTML-based web application or one that does web services. As a matter of fact, a single application can contain both with zero effort.
Now, both of these leverage the spring-boot-starter-web package in order to do the work. And that package has a mixture of components needed to get really get apps up and running from the ground up. The dependencies that are included with spring-boot-starter-web include both Spring dependencies and those from other vendors like Apache and Hibernate, but really Spring Boot is doing all the management of the dependencies, including the versions to ensure that there's no version mismatch.
One of the most popular parts of spring-boot-starter-web is the embedded Tomcat server and by default, you're gonna get that outta the box, which is how you can build an executable jar file that serves a web application. Now that embedded Tomcat can be replaced with Undertow or Jetty, if you prefer, and there's really good documentation in the Spring Boot guide on how to do that transfer from Tomcat to say Undertow. You also can remove Tomcat completely and create a war file instead of an embedded jar, but we'll talk more about that later.
Now, one thing to note is that with Tomcat you get a very opinionated, but default configuration, and it's not the most secure way that you can deploy Tomcat. So you need to consider this in your infrastructure, especially if you're dealing with a cloud deployment where you're going to a public cloud without some sort of a proxy layer in front of your applications. We're gonna go more into how to configure Tomcat in the next video, but for now just keep it in your mind that the default configuration may not be the best for real world examples.
Another set of libraries that you're gonna get with spring-boot-starter-web is a set of JSON marshallers and specifically, you're gonna get the Jackson libraries to do JSON marshalling and unmarshalling. Now, obviously this is very useful for RESTful web services. That's not the only use care for JSON marshallers in an application and I'm sure you can come up with many possible uses, including reading files from the file system or files from a message listener. They're all structured in JSON format.
Now, by default, a Spring application that's serving a response body or accepting a request body, you'll get automatic marshalling and unmarshalling of the JSON payload, but you can always get a handle to that marshaller so that you can do your own in those various use cases. Now if you include the test dependency, you're also gonna get JSON path and by default, you'll get the test dependency if you use start.spring.io and that JSON path allows you to actually test the JSON responses by looking at it from a ex path-like structure.
The Spring Boot also includes the default logging framework. Slf4J is the libraries that they have chosen to do all of their logging and that's what they expose for you to be able to use, as well. Now, Spring Boot builds its own loggers and you can leverage them or you can build your own logger, if you so choose. I traditionally just stick with the one that comes with Spring Boot because it works for all of my needs. You can then leverage properties to modify the logging, the logging formats, or the LogLevel itself.
You're also gonna get a variation of Logback and JBoss logging included for free, if you choose to use those. Now, of course, we're gonna also see Spring libraries 'cause after all this is Spring Boot and one of the first libraries that you're gonna see is Spring Boot auto configure and the Spring Boot auto configure, as we've alluded to already, and we're gonna dig into much more later on, is really what makes all of the magic, so to speak, of Spring Boot happen. You'll also see that the spring-boot-starter-web brings in three separate boot artifacts, the Tomcat starter, the logging starer, which we've just seen has all of those nice dependencies brought in.
You're also gonna get the Boot starter itself and that's what's gonna bring in some of the things that we need to make Boot work. In addition to the Boot starters, you're gonna get some core Spring libraries, as you might expect. You're gonna get Spring core, Spring AOP, Spring beans, Spring context, and Spring expression for those very popular Spring expression language comparisons that you can do when you're dealing with conditional configurations, as well as loading property resources.
You're also gonna get Spring web and Spring webmvc in order to do the web operations. Now, you get a couple more libraries here. The first one we alluded to when we talked about profiles in the Spring Boot application and that's SnakeYAML. SnakeYAML allows you to read those YAML files and convert them to properties at runtime, which you actually can use in your application and you're gonna get a couple validators for both bean validation, as well as simple web validation. Now, each starter, throughout the entire start.spring.io page has its own set of behaviors and properties that it brings in, many of which bring in other starters, as we have seen here with web.
Now this is the knowledge that you really need to grasp and you're only gonna get most of it from experience because this is what's gonna make you more efficient as a developer when writing Spring Boot applications.
- Creating a Spring Boot application
- Configuring a Spring Boot app
- Leveraging profiles
- Packaging and running Spring Boot web apps
- Building a command-line application
- Using Spring Boot starters: Spring Data, Spring Security, and more
- Extending Spring Boot
- Using Spring Boot Actuator to monitor app health and other metrics