Spring initializr: The creator!

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.

  1. 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. Spring Initializr - Google Chrome_007
  2. Let’s discuss each fields. First is type of project. We can choose either Maven or Gradle. Let’s try gradle in this example.
  3. Next is the version of spring boot. We will choose 1.3.5 which is the stable version.Selection_012
  4. Add some project metadata, Group and Artifact. Update if you want or keep it default.
  5. Now lets search for our dependencies. Type web and select the option which say Full-stack web development with Tomcat and Spring MVC. Selection_010
  6. 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 😀
  7. If you see closely we have packaging, please please please choose jar. We are in 2016 as per Josh Long.Selection_011
  8. Spring also provide option to code in groovy and kotlin. We will use Java.
  9. Final step, hit Generate Project. It will download the project in your local. Unzip and import it to your favorite IDE.
  10. 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.nasruddin@nasruddin-studio-1555: ~_013
  11. 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.
  12. 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.nasruddin@nasruddin-studio-1555: ~-Project-spring-boot-tutorials-spring-boot-gradle_018
  13. We can even use ./gradlew clean assemble to clean and compile just like Maven.
  14. 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.Selection_021Test results - Test Summary - Google Chrome_020
  15. ./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.localhost:8080 - Google Chrome_005

Source Code on GitHub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s