In the previous post we had done a lot to get our first spring boot application up and running. In this post we will a very powerful web application which will help us building our production ready application in few seconds.
Let’s do it.
- Open the browser and go to http://start.spring.io/. This will render a page with some inputs, radio, checkbox etc. And yeah that’s the heaven where you just landed.
- Let’s discuss each fields. First is type of project. We can choose either Maven or Gradle. Let’s try gradle in this example.
- Next is the version of spring boot. We will choose 1.3.5 which is the stable version.
- Add some project metadata, Group and Artifact. Update if you want or keep it default.
- Now lets search for our dependencies. Type web and select the option which say Full-stack web development with Tomcat and Spring MVC.
- That’s enough. No wait I want to show one magic. Click on Switch to the full version. Did you see the starter auto-configure options spring provides out of the box. Hugs to Pivotal and Spring team. Josh Long special huge to you 😀
- If you see closely we have packaging, please please please choose jar. We are in 2016 as per Josh Long.
- Spring also provide option to code in groovy and kotlin. We will use Java.
- Final step, hit Generate Project. It will download the project in your local. Unzip and import it to your favorite IDE.
- Open terminal, go to project directory and fire gradle to test you have gradle installed successfully. If not please have a proper installation and understanding of gradle.
- Once you have gradle in your system, fire gradle wrapper in your project directory, this will create a wrapper folder in your project. The Gradle wrapper allows you to run a Gradle task without requiring that Gradle is installed on your system. Isn’t it great. Anyone can clone my project and run it without having gradle installed.
- To compile fire ./gradlew assemble in linux based system or gradle.bat assemble for windows based system. This compile and assemble production code and resources in build sub-directory as project binary artifact. For our project it will be the FAT jar. This will skip unit test. Use ./gradlew clean build to compile and run unit test.
- We can even use ./gradlew clean assemble to clean and compile just like Maven.
- One of most important task is ./gradlew clean check, this will run all the unit test in the application and generate report. You can them out in reports folder in build directory.
- ./gradlew clean bootRun will use bootRun plugin which will assemble the code and run the spring boot application. Now you can open the browser and hit http://localhost:8080/ for your service to be called.
Source Code on GitHub