In this post, we are going to discuss about Spring Boot Initilizr Web Interface and it’s IDEs or IDE Plugins. Before reading post, please go through my previous Spring Boot posts.
Table of Contents
What is Spring Boot Initilizr
Aside from Spring Boot 4 Components, Spring Boot Framework has another important key component that is: Spring Boot Initilizr.
The Spring Team has provided a Web Interface for Spring Boot Initilizr at “https://start.spring.io/” to quick start the Development of Spring Boot Applications using Maven/Gradle build tool very easily.
Why we need Spring Boot Initilizr
The main aim of Spring Boot Initilizr is to start new project development within no time. It provides all required project structure and base build script files to quick start Spring Boot application without wasting time. It reduces development time.
Spring Boot Initilizr is available in the following forms
- Spring Boot Initilizr With Web Interface
- Spring Boot Initilizr With IDEs/IDE Plugins
- Spring Boot Initilizr With Spring Boot CLI
- Spring Boot Initilizr With Third Party Tools
We will look into “Spring Boot Initilizr With Web Interface” now with some examples and will discuss rest of three options in my coming posts.
Spring Boot Initilizr Web Interface
The Spring Team has provided a Web Interface for Spring Boot Initilizr at “https://start.spring.io/“. We can use it to create our new Project’s base structure for Maven/Gradle build tools. It not only generates Project Base structure but also provides all required Spring Boot Jar files.
Spring Boot Initilizr Web Interface looks like this:
NOTE:- Combine above two images to get complete Spring Boot Initilizr Web Interface picture. I was unable to create one single image.
Now we will develop two examples one for Maven and another for Gradle build tools.
Spring Boot Initilizr Web Interface Maven Example
Please follow the following steps to create new Spring Boot WebApplication for Maven Build tool and Spring STS Suite IDE (Or any IDE like Eclipse,IntelliJ IDEA etc).
- Please access Spring Boot Initilizr at “https://start.spring.io/“.
- Provide our project Required details and Click on “Generate Project” Button
- When we click on “Generate Project” Button, it creates and downloads a Maven Project as “SpringMVCMavenProject.zip” file into our local file system.
- Copy “SpringMVCMavenProject.zip” to our Spring STS Suite Workspace and Extract this zip file
- Import this “SpringMVCMavenProject” Maven project into Spring STS IDE
- This “SpringMVCMavenProject” Maven project structure looks like
I have provided all our Maven project’s required details and selected required technologies check boxes as shown in the diagram.
I have selected H2 Database and Click on “Generate Project” Button
If you observe this project files, it generates pom.xml file, two Spring Boot Java files and one JUnit Java file.
“pom.xml”
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.journaldev</groupId>
<artifactId>SpringMVCMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringMVCMavenProject</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
NOTE:- We will discuss about this Java Source code and execution of this code and also discuss about “SpringApplication” class in my coming post.
ServletInitializer.java
package SpringMVCMavenProject;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder
configure(SpringApplicationBuilder application) {
return application.sources(SpringMvcMavenProjectApplication.class);
}
}
SpringMvcMavenProjectApplication.java
package SpringMVCMavenProject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringMvcMavenProjectApplication {
public static void main(String[] args) {
SpringApplication.run(SpringMvcMavenProjectApplication.class, args);
}
}
SpringMvcMavenProjectApplicationTests.java
package SpringMVCMavenProject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration
(classes=SpringMvcMavenProjectApplication.class)
@WebAppConfiguration
public class SpringMvcMavenProjectApplicationTests {
@Test
public void contextLoads() {
}
}
Spring Boot Initilizr Web Interface Gradle Example
Like Maven Example, Please follow the following steps to create new Spring Boot WebApplication for Gradle Build tool and Spring STS Suite IDE.
- Please access Spring Boot Initilizr at “https://start.spring.io/“.
- Provide our project Required details and Click on “Generate Project” Button
- When we click on “Generate Project” Button, it creates and downloads a Gradle Project as “SpringMVCGradleProject.zip” file into our local file system.
- Copy “SpringMVCGradleProject.zip” to our Spring STS Suite Workspace and Extract this zip file
- Import this “SpringMVCGradleProject” Gradle project into Spring STS IDE
- This “SpringMVCGradleProject” Gradle project structure looks like as shown Maven project except pom.xml file change to build.gradle
I have provided all our Gradle project’s required details and selected required technologies check boxes as shown in the diagram.
NOTE:- Here only difference from previous Maven project is Changing “Type” from “Maven Project” to “Gradle Project”. Like this we can select Java Version, Language(Java,Groovy), Required Project technologies etc and create new project very easily.
I have selected H2 Database and Click on “Generate Project” Button
If you observe this project files, it generates build.gradle file, two Spring Boot Java files and one JUnit Java file (These 3 Java files are similar to Maven Project).
Genernate “build.gradle” file content:
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'SpringMVCGradleProject'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-ws")
runtime("com.h2database:h2")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
That’s about Spring Boot Initilizr With Web Interface.
We will discuss about Java Source code, Importance of “SpringApplication” class and its “SpringApplication.run()” method, How to run this Application etc in my coming posts at “Spring Boot Initilizr With IDEs or IDE Plugins”, “Spring Boot Initilizr With Spring Boot CLI” and “Spring Boot Initilizr With ThirdParty Tools” in my coming post.
Please drop me a comment if you have any issues or suggestions.
Hi,
Thanks for the article and it has written in simple way to uderstand the Sping boot Initializr with web interface.
Good Luck!
Hi,
When I try the above steps,
I get the following error:
Non-resolvable parent POM for com.siemens:FirstSpringBootProject:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.2.RELEASE from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.112.215] failed: Connection timed out: connect and ‘parent.relativePath’ points at no local POM @ line 14, column 10 -> [Help 2]
Please help?
Thanks for the article. FYI, there is also a command line tool (try `spring help init`) as well as native integration for curl and httpie (try `curl start.spring.io`) .
Cheers!
Thanks for your suggestions. This is the my first post on Spring Initilizer. I’m going to write few more posts for Spring Initilizer with IDEs, IDE Plugins, CLI, Tools etc. Please wait for upcoming posts to cover all those concepts one by one.