Open In App

What is Spring Cloud?

Last Updated : 16 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

There are many reasons to use Spring Framework for example if you want faster development, less configuration, auto-configuration, embedded server, production-ready application, and many more. But apart from that most importantly we have ready-made support for microservices and this ready-made support is available through Spring Cloud.

Spring Cloud is a collection of projects like load balancing, service discovery, circuit breakers, routing, micro-proxy, etc will be given by Spring Cloud. So spring Cloud basically provides some of the common tools and techniques and projects to quickly develop some common patterns of the microservices.

Spring Cloud Features

Some of the major features that are available in Spring Cloud are listed below

  • Distributed/versioned configuration
  • Service registration and discovery
  • Routing
  • Service-to-service calls
  • Load balancing
  • Circuit Breakers
  • Distributed messaging

Add Spring Cloud BOM to Your Application

To add the Spring Cloud BOM to Your Application you have to add the following dependency.

In Maven:

<properties>
    <spring-cloud.version>2022.0.1</spring-cloud.version>
</properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring.cloud-version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

In Gradle:

plugins {
  id 'java'
  id 'org.springframework.boot' version '3.0.5'
  id 'io.spring.dependency-management' version '1.1.0'
}

ext {
  set('springCloudVersion', "2022.0.1")
}

dependencyManagement {
  imports {
    mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
  }
}

Generate a New Spring Cloud Project

You can create a new Spring Cloud Project by clicking on this link https://start.spring.io/ and choosing your project, language, Sprig Boot version, etc, and the Spring Cloud projects you want to use. Now click on the Add Dependencies button as shown in the below image.

 

Then search Spring Cloud and you can see all the projects that are available in the Spring Cloud displayed below. Please refer to the below image.

 

Once you choose your required Spring Cloud Project then click on the Generate button and your Spring Cloud Project will be generated. Please refer to the below image.

 

Adding Startres to Spring Cloud Project

Spring Cloud projects also include starters that you can add as dependencies to add various cloud-native features to your project. Below is an example of how you would add a Spring Cloud Loadbalancer and a Spring Cloud Netflix Eureka Server, Spring Cloud Openfeign to your application.

In Maven:

<dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    ......
<dependencies> 

In Gradle:

dependencies {
  implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer")
  implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server")
  implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
  ...........
}

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads