From the course: Spring Boot 2.0 Essential Training

Booting from the web

From the course: Spring Boot 2.0 Essential Training

Start my 1-month free trial

Booting from the web

- [Instructor] There are many ways to start a new Spring Boot project. Most of the time I use a plugin that's built into my IDE, and Spring provides a plugin for many IDEs in order to do this. Now, this plugin ultimately is backed by a web service that Spring provides. That web service is also the backer for a site that Spring maintains, and this is by far the most common way to start a new Spring Boot application for those learning the framework. So let's do just that. The place that we will start is in our web browser, and I want you to navigate to start.spring.io. You will see that this will load the Spring Initializr website. This site will allow you to enter some details about your application needs and generate a skeleton. And we're going to do just that. Now one thing to note is that this has changed a few times over its life and will probably change again between now and when you are watching it, but the core functionality has never changed since its introduction. So the first thing that we're going to do is we're going to select Maven project and Java as our language. And I'm going to pick the latest version of Spring that is not a snapshot, which in this case is 2.3.4. Now, we're going to enter some project metadata. So the first thing that I'm going to do is set a group of com.frankmoley.lil.sbet for Spring Boot essential training. And the artifact name that I'm going to call this is booting-web. If you scroll down here, you'll see that there's a description and a package name. And that package name becomes very important because you're going to see later that an application class gets created there. Now for packaging, we're going to select jar and then Java 11 as our runtime. Now we're going to come up here to dependencies and we're only going to add one dependency for right now. And that dependency that we are going to add is Web. So just type in web, it brings up Spring Web, select it, and now generate. Now this is going to cause a zip to be created and downloaded. Now what I want you to do is to copy that zip file to wherever your working directory is, whether you're working from the exercise files or wherever. So I'm just going to do a cp from the downloads directory and it will be called booting-web.zip. And I'm going to copy that here to my local directory, and then I'm going to unzip it. And now I'm going to remove the file itself. Excellent, so now I can import this into my IDE. So I've got my IDE here. Let me go to my modules. Let me select my modules, and let me import this as a module. We're going to select Maven as the import. And we will hit OK. Okay, we will allow Maven to do its import, and we're going to make this relatively simple. We're going to open up this package and go to source, main, resources. And in the static directory, we're going to create a file called index.html. And all we are going to do here is put an html tag and a body tag, and a h1 tag that says, "Hello LinkedIn Learning." And now we will go to our main boot application and run that application. So we're just going to run the main method. Now we'll explain all of this in later videos, so don't worry, but you will notice here that we have a message second to the bottom that says Tomcat started on port 8080. So let's jump back to our web browser and let's go to localhost:8080, and you'll see that we served the webpage from our application. And that's as simple as you can get it. We created a web application and started it up in a matter of minutes using Spring Boot, and the start.spring.io website.

Contents