Spring Boot

What is Spring Boot?

It is a Spring project aim to create easy web or stand-alone applications. It provides the next features:

  • No XML configuration is required
  • Tomcat embedded
  • Convention over configuration
  • Easy setup
  • Very lightweight
  • Easy to test
  • You can create web, standalone, API or executable applications

This tutorial shows you how to create a simple Spring Boot project with this features:

  • Gradle Build
  • Maven Build
  • Basic configuration

You can create this project from command line like this:

Using Gradle

spring init --dependencies=web --build=gradle --language=java spring-boot-setup

That command will generate a Spring project structure under spring-boot-setup folder.

In order to do that you need to install SDKMAN if you are using Linux or Mac, or posh-gvm if you are using Windows. After that, you can easily install:

  • Spring Boot
  • Gradle or Maven

I will show you a short version of build.gradle generated.

buildscript {
	ext {
		springBootVersion = '2.0.3.RELEASE'
	repositories {
	dependencies {

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.jos.dem.springboot.setup'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {

dependencies {

This project will generate an DemoApplication.java file.

package com.jos.dem.springboot.setup;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);


Next let’s create a simple rest controller as follow:

package com.jos.dem.springboot.setup;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

public class DemoController {

  public String index(){
    return "Hello World!";


Now, in order to run it, use this command line.

gradle bootRun

Finally you can go to this address: http://localhost:8080/ and you will see our hello word message.

Using Maven

You can do the same using Maven, the only difference is that you need to specify --build=maven parameter in the spring init command line:

spring init --dependencies=web --build=maven --language=java spring-boot-setup

And when you run your project use this command:

mvn spring-boot:run

This is the pom.xml file generated:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


	<name>Spring Boot Setup</name>
	<description>Demo project for Spring Boot</description>







To browse the project, go here

Return to the main article

comments powered by Disqus