Hey there, welcome back friends. In our last video, we have created our first Spring Boot application. And today we will be creating our first Spring Boot web application. So this is interesting are definitely over courses dedicated towards the Spring Boot with RESTful API, but we will also check quickly how to create a web application using Spring Boot. So this is kind of a bonus thing which you are getting in here. All right, now let us navigate to file new and this time, we won't create a Maven project rather we will take a shortcut and make use of this particular feature which comes with a spring tool suit which is nothing but a spring starter project.
So this is good and this will save over time. And when we create a spring start a project. It will fetch the information from this URL which is the start dot spring dot Io and we must have internet connection. All right. Now let us give the name as a web app with a Spring Boot you can give any other name as well. And artifact can be like a spring web app with Spring Boot.
And based on your requirement, you can make changes Alright, so the setting is good enough for me. Let me click on next and in here that is something which is important. The current version which we are using as a Spring Boot 2.0 point five, which is the latest stable build and injure as we are planning to build a web project let us add in the web dependency, so search for web and in here, select option web and click on Next. Now this particular project would be created by taking help of spring.io. And in the background, it will take couple of seconds to fetch the information from the URL based on the internet speed. All the jar files will be also added.
Now, thanks to when we create our application by taking help of start a project, there are like couple of things which we get readymade. For example, if I show you Java resources, we have this package or dot study z. And in here there are like couple of classes which are already built. Now, the name of the package needs to be given where when we create a new spring starter project, we have the option to give the package name so, the package name would be derived from here. So, these options are again important. So, whenever you start with a new project, take note of these small little details All right, let me close this alright so, the package is created for us application is created.
Now, this particular line is the exact same line which we have created in our last video. And this line creates our spring application right. Apart from that we also have the servlet initializer. This is used in order to create for example, web application. Alright, so this is again created. Apart from that if I show you the Resources folder we have couple of more things.
For example, application dot property, we will talk about application property later down the line. And apart from that we also have the folder created by the name of web apps. Currently, there are like no files inside this web apps folder, but this is the default location where they will place the view files. Now, this is cool. This is nice that we have like a lot of the things already set up by taking help of a starter project. All right.
Now friends, there are a couple of things this particular statement does. First of all, as we know, Spring Boot is opinionated, the default values are already set. So this particular statement will load up with the default values. This web app is the default location of the view files. Let me also do one small little thing. If I right click Navigate to Java EE tools, I can also create the web dot XML file, the web dot XML file would be created inside this web m folder.
If I show you the web info folder there are like default file name as well, for example, index dot HTML or index dot JSP. Now friends when it comes to Spring Boot Spring Boot by default, it doesn't support JSP. So for example, we create a HTML file, then this HTML file would be treated as the home page. Let me show you. So in here, if I create a new HTML file by the name of index dot HTML, and give the body as a homepage, and title as homepage. Now, let me quickly show you that how this particular run method will load up the default page.
So in here, let me quickly run this. Let me right click by highlighting this application or Java file. We can either This as a Spring Boot, or we can also run this as Java application. Now, if you won't run this as on the server, you don't require it. And we will talk about this particular point in a minute. Let us run this as a Java application.
Alright, so this line loads up the default configuration. And if the default configuration are loaded properly, then we would be able to load up our homepage on this URL, localhost colon 8080. Let me show you. And here is the homepage. So this fact that we are able to load our homepage very quickly using the Spring Boot application proves the fact that definitely this line loads the defaults, first of all. Now, the next thing this particular line does is starting the Spring Boot app, which is by default is very understandable because the Spring Boot application is up and running.
And we can identify this fact by checking out this particular line which says started application right. So, the next thing this line does is starts the boot app right then Apart from that, this application also performs class path scan. Now, what exactly is this class path scan in order to understand this, I will be like creating a yet another class inside this package or to study easy So, let us quickly create this class by the name of web controller. Here we go and let me click on Finish. Now, friends take note of it that this particular controller has no association no reference in here, this run method is independent right. So, in here, first of all I will mark this particular class as controller.
Friends when it comes to modern application, modern application are shifting towards the annual data Class convention where we annotate a specific class and based on these annotation that classes will perform a specific task. Similarly, when it comes to Spring Boot annotations are very important. And in here, we are simply marking this as controller, and this class would be treated as a controller. So let us control a URL pattern. So in here, in order to control a URL pattern, let us create a public method. The return type would be string.
And in here, we will give the name as welcome maybe Pico, and we will return for example, welcome dot html. Here we go. So this is good. Now we need to also provide a pattern, the URL pattern this method will handle. So in here, let me again make use of our annotation by the name of request mapping. And we will, like give a URL pattern and the pattern would be for example, welcome.
All right. Now finally, let's go quickly create this welcome dot html file. Again, we will like choose the default location. default location is inside this web apps folder. I will right click navigate to new and create a new HTML file by the name of welcome dot html. Here we go.
And we'll give the title as welcome and party. So, welcome again coolest stuff right and our work is done. Now how our work is done and how easily this application has been built. The reason is class paths can when now we will start this application Spring Boot will perform a class path scan and it will register this particular class as a controller and it will provide the mapping Welcome to this method and as a result we would be able to handle the scenario accordingly. Now friends that is a small little thing when it comes to Spring Boot, we make use of Embedded Tomcat, right? So embedded Tomcat is used.
And the reason why it is possible is because one of the dependency let me show you the dependency real quick again. So if I show you the dependency, the Maven dependency in here we have something known as Tomcat embed code, right? So this jar file is responsible in loading the Tomcat web server embedded. So this Embedded Web Server is locally available, we need not to deploy this application on a web server. And this is amazing. This is cool.
This is nicer stuff, right? So this is the fourth thing, this particular run method does. So the fourth thing is it starts local Tomcat. All right. Now friends, these are the four things this particular single statement does which is amazing right. Now friends, the length of the video is pretty high.
So we will continue our discussion in our next video. Do I hope you guys enjoyed this video thanks for watching, have a nice day and take care