In this post, we are quickly covering various features of the Spring Initializr tool.
Spring Initializr provides a simple and intuitive web UI to create and configure and generate Spring based application. This tool makes it easy for developers to generate an initial project structure without worrying much about the project structure and dependencies. On a high-level Spring Initializr tools take cares of the following points for any Spring based application
Spring Initializr is available on the web, most of the IDE has a built-in integration with the Initializr.
Let’s look at the Initializr interface to start with. Go to start.spring.io, you will have a similar screen.
This is the simplest Initializr view with minimal options to build your project. Let’s quickly discuss these fields for a basic understanding.
groupIdattribute in Apache Maven, also known as the id of the project’s group.
artifactIdattribute in Apache Maven.
Once you provided these details, click on the “Generate Project” button. Spring Initializr provides a zip file containing a Maven/Gradle project. Below is the structure for our generated Maven project.
mvnw mvnw.cmd pom.xml src ├── main │ ├── java │ │ └── com │ │ └── javadevjournal │ │ └── springinitializrsample | | └── SpringInitializrSampleApplication.java │ └── resources │ ├── application.properties │ ├── static │ └── templates └── test └── java └── com └── javadevjournal └── springinitializrsample └── SpringInitializrSampleApplicationTests.java
Above structure automatically created by the tool based on the chosen dependencies. Since we chose “web” as our dependencies, Spring Initializr has detected it is a web application, a
templates directories created to hold your static resources and UI templates.
Spring Initializr is smart enough to include Maven wrapper in the project structure. This wrapper makes sure we don’t have to install Maven to run this project.
To build and run this application without installing Maven use the following command
Above section describe the least view of the tool, It also offers an advance view of the advanced users. Click on the “Switch to the full version” link to get this view.
Let’s look at a few of the advanced properties (We already covered a few in Section 1)
Apart from this, Spring Initializr provides a detail view of the dependencies section where we can choose different dependencies required for our application. Here is a partial view of this section.
There are certain use cases when a certain dependency is not available in the given Spring Boot version. If you ever face such issue, click on the advanced section to see if the required dependency is available in the selected version of the Spring Boot.
This service comes with certain default values to generate a new project with minimum fuss. In case you don’t give these values, the Initializr service will pick these default values while generating your project structure. Here are the default configurations for your reference
If you don’t like the web interface or more comfortable using command-line tools, the Initializr service offer an option to use the command line for generating a project structure for your application. We can use
If you run
curl start.spring.io in the command line, you get a response from the service, at the end of the response, you may find a similar output
To create a default demo.zip: $ curl https://start.spring.io/starter.zip -o demo.zip To create a web project using Java 10: $ curl https://start.spring.io/starter.zip -d dependencies=web \\ -d javaVersion=10 -o demo.zip To create a web/data-jpa gradle project unpacked: $ curl https://start.spring.io/starter.tgz -d dependencies=web,data-jpa \\ -d type=gradle-project -d baseDir=my-dir | tar -xzvf - To generate a Maven POM with war packaging: $ curl https://start.spring.io/pom.xml -d packaging=war -o pom.xml
Either you can use one of the above options to generate a project for your application or you can pass information to the service to generate a project based on your requirements. Let’s assume, we like to generate a web project based on Spring Boot 2.0.5.RELEASE using web and devtools as dependencies.
curl https://start.spring.io/starter.zip -d dependencies=web,devtools \ -d bootVersion=2.0.5.RELEASE -o javadevjournal-initializr-project.zip
All the major Java IDE provides a built-in support for the Spring Initializr. Following IDE provides built-in support for the Initializr service.
Here is a quick video to get you started with Spring Initializr:
In this post, we discuss different features of the Spring Initializr service. We discuss the different options like a web, command line and IDE for using this service. Initializr is a powerful service which helps to create to speed up project bootstrapping by taking out the setup complexities. There is a minimal code involved, and the service has a rich configuration structure, allowing you to define not only the values of various project attributes but also the list of dependencies and the constraints to apply to them.
Hello!! I am Umesh- an engineer by profession and a photographer by passion.I like to build stuff on the web using OSS and love to capture the world through my lens.
Spring Boot Security Auto-Configuration23 Apr, 2019
Spring Boot Change Context Path16 Apr, 2019
Configuring Hikari Connection Pool with Spring Boot12 Mar, 2019
Spring Boot With Ehcache08 Mar, 2019
Custom Validation MessageSource in Spring Boot05 Mar, 2019
Spring Boot Rest Example