From the course: Spring Boot 2.0 Essential Training

Understanding Spring Boot dependencies

From the course: Spring Boot 2.0 Essential Training

Start my 1-month free trial

Understanding Spring Boot dependencies

- [Instructor] Before we get started building a web applications with Spring Boot, I want to 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 going to use this as an example of what comes with the traditional starter. Central using web starters are baseline. Let's just discuss what comes with them with web applications. Now in the spring world, and especially with Spring Boot, there's no difference between the 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 module in order to do the work. And that package has a mixture of components needed to get apps up and running quickly from the ground up. The dependencies that are included with spring-boot-starter-web include both spring dependencies and those from vendors like Apache but really Spring Boot is doing all of 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. By default, you're going to get that out of 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 jetty or other app servers, if you prefer. And there's really good documentation in the Spring Boot guide on how to do that transfer from Tomcat to something else. You can also remove Tomcat completely and create a WAR file instead of an executable JAR, if your use case requires that. Now one thing to note, is that the Tomcat you get is very opinionated but default configuration, and it's not the most secure way you can deploy on to Tomcat. So you need to consider this in your infrastructure especially if you are dealing with cloud deployments where you're going to public clouds without some sort of proxy layer in front of your applications. We're going to go more into how to configure Tomcat in the next video, but for now, just keep it in mind that the default configuration may not be the best for real-world examples. JSON Marshaller is another value out of Spring Boot. With spring-boot-starter-web, you get a set of JSON Marshaller specifically from the Jackson libraries, to do JSON marshaling and unmarshalling. Now, obviously this is very useful for RESTful web services but that's not the only use case for JSON Marshallers in an application. And I'm sure if you come up with some many possible use cases just by thinking about it, including things like reading from the file system or reading from a message listener, as long as they're structured in JSON format. Now, by default, a spring application that's serving a response body, or accepting a request body, specifically of a web service application path, you're going to get automatic marshaling and unmarshalling of the JSON payload. But you can always get a handle to that. Marshaller so that you can do your own in the various use cases that you come up with. By default, you're also going to get some test dependencies that help you test the web services themselves to things like JSON path. Spring Boot also includes a default logging framework . SLF4J is the chosen library, and they do all of their logging with that, and expose it for you to use as well. Now, Spring Boot does build its own loggers and you can leverage them or you can build your own logger if you choose. Now, I traditionally just stick with the one that comes with Spring Boot because it works for my needs. You can leverage properties to modify the logging, the logging formats, or the log level itself. You're also going to get a variation of log back logging included for free if you choose to use that. Now, of course, you're going to see spring libraries because after all this is Spring Boot. One of the first libraries that you're going to see is Spring Boot auto-configure. And we've already alluded to this, in how spring does auto configuration. And we'll dig into it a little bit more. But again, this is where the magic of Spring Boot comes from. You'll also see that spring-boot-starter-web brings in the three separate boot artifacts, Tomcat starter, and a logging starter, which you've just seen. All of those is a nice dependency mix that comes with it. But 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, beans, context, expressions, and those are used for those spring expression language constructs. You're also going to get the ability to load property resources through those core libraries. You're also going to get Spring Web and Spring WebMvc in order to do our web operations. Now, there's just a few more libraries here that you're going to get. One of the first ones that we've actually used is SnakeYAML. SnakeYAML is what allows us to read those YAML files for application at YAML, and convert them to properties at runtime which you can actually use within your application. Now you're also going to get a starter test module. And this includes J unit as well as everything that you need to test a Spring Boot application. Now each starter throughout the entire starter next spring that out page, has its own set of behaviors and properties that it brings in, many of which bring in other starters as well. This is going to take you quite a bit of knowledge to grasp what you get, and it's not something that we can wrap into a course. It's something that you're going to have to get by using Spring Boot in various methods throughout the examples that spring provides.

Contents