Take a look at the default dependies included in Spring Boot for web.
- [Instructor] Before we get started building web applications with Spring Boot, I want to talk a little bit about what comes with the Web Starter. And web applications are by far the most common place to start with Spring Boot, so we're going to 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 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-stater-web package in order to do the work. And that package has a mixture of components needed to really get apps up and running from the ground up. The dependencies that are included with spring-boot-stater-web include both Spring dependencies and those from other vendors like Apache and Hibernate, but really Spring Boot is doing all the management of dependencies including the versions to ensure that there's no version mismatch.
One of the most popular parts of spring-boot-stater-web is the embedded Tomcat server, and by default you're going to get that out of the box, which is how you can build an executable .jar file that serves 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 got 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 proxy layer in front of your applications. And we're going to 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 going to get with spring-boot-stater-web is a set of JSON Marshallers, and specifically you're going to 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 case for JSON mashallers 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 automatical 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 going to 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 x path like structure.
And the Spring Boot also includes a default logging framework. Slf4J is the libraries that they have chosen to do all of their logging, and that's what they expose for your 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 format, or the log level itself.
You're also going to get a variation of Logback and JBoss logging included for free if you choose to use those. Now of course we're also going to see Spring libraries, because after all this is Spring Boot. And one of the first libraries that you're going to see is Spring Boot auto configure. In the Spring Boot auto configure as we've alluded to already and we're going to dig into much more later on, is really what makes all of the magic so to speak of Spring Boot happen. You also see that the spring-boot-stater-web brings in three separate boot artifacts, the Tomcat starter, the logging starter, which we've just seen has all those nice dependencies brought in, you're also going to get the Boots starter itself and that's what's going to bring in some of the things that we need to make Boot work.
In addition to the Boot starters, you're going to get some core Spring libraries as you might expect. You're going to 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 going to 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 that you actually can use in your application. And you're going to get a couple validators for both bean validation and 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 going to get most of it from experience, because this is what's going to 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