Categories: Spring BootTutorial

Spring Boot Initializr with Spring Boot CLI

Hello friends lets discuss another way to create spring boot project structure by using Spring Boot Initializr. Spring Boot Initializr is used to quick start new Spring Boot Maven/Gradle projects within no time. It generates initial project structure and builds scripts to reduce Development time.
As previous chapter we have seen following ways for Spring Boot Initialzr.
Before starting discussion for this tutorial we have to go through my previous chapter (Spring Boot CLI installation and Hello World Example) for Basic and Installation guide for Spring Boot CLI. As in previous chapter we saw, the Spring Boot CLI is a great way to develop Spring applications by just writing code. However, the Spring Boot CLI also has a few commands that can help us use the Initializr to kick-start development on a more traditional Java project.
Spring Boot CLI provides a “spring init” command to bootstrap Spring Applications.
Syntax for Init Command:

spring init [options] [location]
Here “options” are command options and “location” is specified our file system location to create new Spring Boot Project.
Examples for Spring Init Command:
Example 1: Use default setting

$ spring init
After contacting the Initializr web application, the init command will conclude by downloading a demo.zip file with following default setting.
  • Default Build tool is “maven”.
  • Default Spring Initilizr service target URL: https://start.spring.io
  • Default project name: “demo
  • Default maven type: “jar
  • Default only baseline starter dependencies for Spring Boot and testing
Example 2: Using required dependencies on web project
Let’s say you want to start out by building a web application that uses JPA for data persistence and that’s secured with Spring Security. You can specify those initial dependencies with either –dependencies or -d:
$ spring init –dweb, jpa, security
This will give you a demo.zip containing the same project structure as before, but with Spring Boot’s web, JPA, and security starters expressed as dependencies in pom.xml.
Example 3: Using required dependencies on web project with change Build (Maven to Gradle)
For Gradle
$ spring init –dweb, jpa, security –build gradle
For Maven
$ spring init –dweb, jpa, security –build maven (maven is default build type)
Example 4: Change packaging
By default, the build specification for both Maven and Gradle builds will produce an executable JAR file. If you’d rather produce a WAR file, you can specify so with the –packaging or -p parameter:
$ spring init –dweb, jpa, security –build gradle –p war
Example 5: Change application name
$ spring init –dweb, jpa, security –build gradle –p war myapp.zip
Example 6: Specifying the Java version to compile with, and selecting a version of Spring Boot
$ spring init –dweb, jpa, security –build gradle –java-version=1.7 –boot-version=1.3.0.RELEASE –p war myapp.zip
Other more commands
We can discover all of the parameters by using the help command:
$ spring help init
For lists several parameters that are supported by the Initializr.
spring init -l 

Summary

Whether we use Initializr’s web-based interface, create our projects from Spring Tool Suite, or use the Spring Boot CLI to initialize a project, projects created using the Spring Boot Initializr have a familiar project layout, not unlike other Java projects we may have developed before.

Happy Spring Boot Learning 🙂

Previous
Next
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

2 years ago