Welcome back! In this step, we would look at starters.
We would look at a couple of example starters. Spring Boot starter web and Spring Boot starter JPA.
If you open up the pom dot xml of the project that we have created earlier, you would see
that it's using Spring Boot starter web.
How did it use Spring Boot starter web?
That's because we configured a dependency on web in here.
So if I open that up and go to the pom dot xml, youd see that Spring Boot starter web is configured in
here.
So this Spring Boot starter web is the preferred stater for Spring Boot to develope web applications
as well as RESTful web services.
So if I go control and hover over it or command and hover over it and click open pom dot xml for Spring Boot
starter web you would see that it defines varied kind of dependencies.
So what does it really define?
Let's look at it. When we run the application, we were automatically using Tomcat. Thats because of this Spring Boot
starter Tomcat.
If you look at Spring Boot starter web,
it contains a dependency on Spring Boot
starter Tomcat and that's how the application is automatically running in
Tomcat. The other things which you would seen here are Spring web and Spring web MVC. Spring MVC
as you would know is this Spring MVC framework. If I add in a Spring Boot starter web, I automatically get Spring
MVC, I automatically get validation. Validation -
the default implementation for Java validation API is hibernate validator.
So I get that as well and I get Tomcat.
And, also I get the starter JSON. Starter JSON is more for RESTful web services.
We saw that when we actually invoke the RESTful web service, the conversion to JSON automatically happen. If
you actually looked at our code,
We just returned the bean back. So in the booksController, what we're doing is we are just returning a
list of beans back.
How does it automatically convert it to JSON? That's done through this starter.
The starter JSON brings in the JSON into the picture.
Basically when you look at all starter projects, they have a set of dependencies that are already defined.
And these dependencies are automatically provided to our project.
So when I add in Spring Boot starter web, I get all these dependencies. So you'd see that I'm getting
Jackson for handling all the JSON stuff. You'd see that I'm getting Tomcat.
So that I can the application in Tomcat. I'm getting hibernate validator and validation API for doing the validation.
Im getting this Spring framework because I have a dependency on Spring web and that could have dependency
on Spring framework.
And, also I would get the logging frameworks as well because the logging frameworks are by default defined
in the Spring Boot
starter. So Spring Boot starter is one of the dependencies in Spring Boot starter web.
So if you open up the pom dot xml for it,
So this is the default starter.
This is where everything inherits from. So any starter that you would use in Spring Boot, it inherits from
Spring Boot starter and you would see that these are the dependency and Spring Boot framework.
This has a dependency on Spring Boot auto configure.
That's how we get auto configuration.
This has a dependency on Spring Boot starter logging.
That's how we would get logging.
And we have a dependency on Spring core as well.
YML is one of the configuration languages that Spring Boot supports.
So we also have snake YML in here.
Thing about Spring Boot starter web is once it brings in all these dependencies, what would kick in? Auto
configuration would kick in.
Because the spring web MVC contains dispatcher servlet. So automatically dispatcher servlet would
be configured.
That's done by the Spring Boot auto configure. Thats the auto configuration which we talked about earlier.
Spring Boot starter web is one of the starter. The other starter you can see in here is Spring Boot starter
test. Spring Boot starter test enables you to write unit test and integration tests as well.
So if I go to the pom dot xml in here, you would see that it has a definition on spring boot test.
It has a definition on the auto configured for Spring Boot test and it has dependencies on Junit framework.
AssertJ.
And also you have Mockito. Mockito is the default mocking framework that comes along with Spring Boot.
A combination of AssertJ and Hamcrest are awesome to write great matches.
And you also have a dependency on the spring test framework which is useful in writing unit tests for
spring.
So until we looked at a couple of starters which are Spring Boot starter web and Spring Boot starter
test.
Other than that, another important starter which is frequently used as a Spring Boot starter JPA.
If you know JPA, JPA is kind of the interface for hibernate. So JPA defines how ORM applications or ORM frameworks
should work. ORM is object relational mapping. Let's now add in a dependency on Spring Boot starter JPA. You
would see now that there would be a lot more Maven dependence which would come in.
Actually, it's Spring Boot starter
data JPA.
So now we have hibernate core, hiberante JPA. We have javax transaction api, hibernate common annotations.
You have spring data, spring data JPA, spring ORM, spring tx and a lot of such dependencies
come in. That's because of the Spring Boot starter JPA.
So if you open up the pom dot xml for spring boot starter JPA then you would see all of the dependencies
that are listed down. So this has a dependency on spring boot starter AOP, starter JDBC, hiberante transaction
API and spring data JPA.
So all this jars you'd get. As soon as I add in a spring starter data JPA, I would get all these
things for free.
One of the things you need to remember is if you are a starting programmer or this is the first time
you are looking at Spring Boot, a lot of things might be confusing to you. Especially because we are referring
to so many different terminologies.
Spring Boot solves problems for wide variety of frameworks. So there are a lot of terminologies that
come into picture when we talk about spring boot.
So if you're not able to understand any of these terminologies do not worry at all.
Over the course of this course and also over the course of your next few years, you'll learn sufficiently
enough so that those terminologies become really clear for you.
The idea for you is to understand the big picture of what Spring Boot does.
Spring Boot is now one of the most popular frameworks to develop.
micro services. The idea behind the whole set of these steps is to give you a flavor of Spring Boot in
a wide variety of scenarios.
If you are not able to understand a couple of scenarios that's not a problem at all.
With that disclaimer, let's end this step here.
And I look forward to see you in the next step.