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
  • Netty (Starter Webflux) or Tomcat (Starter Web)
  • Convention over configuration
  • Easy setup
  • Very lightweight
  • Easy to test
  • You can create web, standalone, API or executable applications

This post 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
  • Java

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

buildscript {
  ext {
    springBootVersion = '2.0.6.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 {

org.springframework.boot plugin activate spring-boot-gradle-plugin, io.spring.dependency.management plugin supports Maven. boot:spring-boot-starter-test pulls in Spring Boot Junit, Mockito, Spring Test and more.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);


@SpringApplication annotation allows Spring Boot to scan recursively for beans inside this package and register them, also indicates this class is a source of beans definitions. 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 code go here, to download the code:

git clone git@github.com:josdem/spring-boot-setup.git

Return to the main article

comments powered by Disqus