Learn how to build, deploy, and run a Spring Boot application at the command line.
- [Instructor] Before building, let's make sure that Java and MVN have been properly installed. I opened up a terminal window and my present working directory is explore cali. So we want to type java dash version and we correctly have java version 1.8. Now, let's check that MVN is properly installed. Mvn space dash version and that is properly installed.
If either of these commands fail, then refer to the installation instructions of those products. Now let's build the project. In our terminal window, in this folder we type mvn space install, mvn install. Now this will download all the dependencies into the dot m2 repository, it compiles any dot java sources and packages them into 1.jar file. It will take several minutes to download the dependencies for the fist time into your local mvn repository.
So, mine is finished and let's just prove that it built, there's now a target folder. We see the explorecali dash 0.01 snapshot.jar and that's what we're going to run at the command line. So we type java dash jar target explore cali and the dot jar file and enter. After a lot of start up messages, we finally know the application is running when it prints started at explore cali application.
I know by default that spring boot microservices use port 80 80, let's see if the application is accepting a request via the browser, so I'm opening the browser and I'm going to just hit that application 80 80 and see if it's listening, so local host 80 80. And, it prints a java packet, don't worry about the meaning of this message, it's basically saying "I'm alive." If there was any problem the browser will respond with a message such as site can't be reached.
Now we can have multiple instances of the application, but only if they are listening on different ports. If we attempt to run them on the same port, the second instantiation will fail. So, let's open up a different terminal window down here and we're in the same folder. Now, this time we're going to invoke the port 90 90, so we're going to type java dash jar dash d server dot port equals 90 90 and then the jar file, target slash explore cali dot jar.
We're going to launch that and it's running and it seems to be just starting up. To prove that it's listening on 90 90, let's type local host 90 90. See how easy it is to run multiple instances of a web application. To halt the application just go back to the terminal window and hit control c, or use your operating systems process controller system to terminate it.
To do this in a classic web archive or a war file, would require us to have multiple installations of tomcat running on different ports. This is the beauty of a microservice, it's completely self contained with a light footprint and it's runnable with a single command. This makes it a favorite with the dev ops and cloud computing crowds because the web application and server start up can be scripted as one command. Without implementing any of the explore California solution, we can see that the spring boot project is already equipped with the basic plumbing required by most web applications.
- Setting up the project
- Building, deploying, and launch the microservice
- Declaring Spring Data JPA repository interfaces
- Invoking repositories
- Using Spring Data query methods
- Exposing RESTful APIs with Spring Data REST
- Using the /search resource to invoke query methods
- Paging and sorting
- Declaring a new REST controller
- Creating HTTP methods for creating, reading, updating and deleting persistent data.