Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Spring Boot 2.0

You're reading from   Mastering Spring Boot 2.0 Build modern, cloud-native, and distributed systems using Spring Boot

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781787127562
Length 390 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dinesh Rajput Dinesh Rajput
Author Profile Icon Dinesh Rajput
Dinesh Rajput
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting Started with Spring Boot 2.0 FREE CHAPTER 2. Customizing Auto-Configuration in Spring Boot Application 3. Getting Started with Spring CLI and Actuator 4. Getting Started with Spring Cloud and Configuration 5. Spring Cloud Netflix and Service Discovery 6. Building Spring Boot RESTful Microservice 7. Creating API Gateway with Netflix Zuul Proxy 8. Simplify HTTP API with Feign Client 9. Building Event-Driven and Asynchronous Reactive Systems 10. Building Resilient Systems Using Hystrix and Turbine 11. Testing Spring Boot Application 12. Containerizing Microservice 13. API Management 14. Deploying in Cloud (AWS) 15. Production Ready Service Monitoring and Best Practices 16. Other Books You May Enjoy

Setting up a Spring Boot workspace

Let's see how to set up a Spring Boot workspace to create a Spring Boot application. No special tool integration is required to set up a Spring Boot application. You can use any IDE or text editor. But, Spring Boot 2.0's minimum system requirements are as follows:

  • Java SDK v1.8 or higher
  • Spring Framework 5.0.0.RELEASE or above
  • Maven (3.2+) and Gradle 4
  • Tomcat 8.5, that is, a Servlet 3.0+ compatible container

Let's see the following ways to set up the workspace for the Spring Boot application:

  • Set up Spring Boot with Maven
  • Set up Spring Boot with Gradle

Now, we will explore how to set up a Spring Boot application with Maven and Gradle in detail.

Setting up Spring Boot with Maven

Spring Boot is compatible with Apache Maven 3.2 or above. If your machine doesn't already have Java 8 or above, first download Java 8 or above from Oracle's official website:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

And if you don't already have Maven, first download it from https://maven.apache.org/; Ubuntu users can run sudo apt-get install maven. Let's see the following Spring Boot dependencies with the org.springframework.boot groupId:

<?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">
   <modelVersion>4.0.0</modelVersion>

   <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>2.0.2.RELEASE</version>        <relativePath/> <!-- lookup parent from repository -->   </parent>

   <dependencies>
        <dependency>               <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>    
</dependency>
</dependencies> ... ... </project>

This .pom file is the minimum requirement for the Spring Boot 2.0 application.

Let's see the Gradle setup for the Spring Boot application.

Setting up Spring Boot with Gradle

We have seen that Java 8 is the minimum requirement for Spring Boot 2.0, both with Maven and Gradle. However, if you want to use Gradle, then first install Gradle 4 or above in your machine from www.gradle.org/.

Now, see the following Gradle Spring Boot dependencies file with org.springframework.boot groupId. Here's what the build.gradle file should look like:

buildscript {
   repositories {
         jcenter()
         maven { url 'http://repo.spring.io/snapshot' }
         maven { url 'http://repo.spring.io/milestone' }
   }
   dependencies {
         classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7'
   }
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
   baseName = 'HelloWorld'
   version =  '0.0.1-SNAPSHOT'
}

repositories {
   jcenter()
   maven { url "http://repo.spring.io/snapshot" }
   maven { url "http://repo.spring.io/milestone" }
}

dependencies {
   compile("org.springframework.boot:spring-boot-starter-web")
   testCompile("org.springframework.boot:spring-boot-starter-test")
}
 

The preceding Gradle file has minimum requirements for the Spring Boot application. You could use either Maven or Gradle since the process is the same. Spring Boot creates an application using the same process.

Let's create your first Spring Boot application and see how to set up the project's structure using Spring Boot Initializr.

You have been reading a chapter from
Mastering Spring Boot 2.0
Published in: May 2018
Publisher: Packt
ISBN-13: 9781787127562
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image