spring cloud 越来越流行了,当初学习的时候都是使用maven构建的cloud(网上很多的springcloud案例也是通过maven构建的,gradle构建的cloud资料很少,或者说不全面),所以我一直想使用gradle构建一个cloud的demo.上周花了一个晚上整了一个demo,今天找个时间写一篇博客记录下…
直入主题>>>>>>

使用的版本如下:
springBootVersion = '2.0.1.RELEASE'
springCloudVersion = 'Finchley.RELEASE'
需要对应:
可以去springcloud官网查看springboot对应的springcloud版本
https://spring.io/projects/spring-cloud
这里贴出来…
使用gradle构建spring cloud,搭建一个cloud的helloworld
整的时候遇到了一个小坑就是dependencyManagement插件问题,这个插件主要是解决cloud零散jar的版本问题,我之前使用maven构建的使用就是因为这个插件安装失败,所以很难受,一个jar的版本都需要自己控制,这次使用gradle构建的使用使用了dependencyManagement插件后很舒服,直接引用对应的jar即可,版本不需要自己管理了…

这里使用一个demo案例主要实现

  1. eureka的服务注册与发现
  2. 微服务基于Feign的调用
  3. 服务的熔断器hystrix

这里使用的比较简单,主要是作为一个spring cloud 的一个 hello world

其他组件在上面进行扩展即可,比如说一些常用的组件

  • spring-cloud-config 配置
  • spring-cloud-gateway 网关
  • spring-cloud-bus 消息总线
  • spring-cloud-security 安全认证
  • Spring Cloud Zookeeper 服务注册与管理

现在先来看看整体效果吧
启动顺序

  1. eureka
  2. user
  3. test

使用gradle构建spring cloud,搭建一个cloud的helloworld

贴出一个关键的配置

  1. cloud_demo.build.gradle
group 'cn.shaines'
version '0.1.1'

buildscript {
    ext {
        // 定义变量
        springBootVersion = '2.0.1.RELEASE'
        springCloudVersion = 'Finchley.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

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

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    dependencyManagement {
        imports {
            // 解决cloud零散jar的版本问题
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
    }

    // 统一移除jar
    /*configurations {
        all*.exclude module: 'spring-boot-starter-logging'
        all*.exclude module: 'logback-classic'
    }*/

    repositories {
        mavenCentral()
    }

    dependencies {
        compile('org.springframework.boot:spring-boot-starter')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.springframework.boot:spring-boot-starter-test')
        // compile ':spring-cloud-starter-config'
        // compile ':spring-cloud-starter-eureka'

        // compile(group: 'com.qcloud', name: 'cos_api', version:'4.4') {
        //     exclude(module: 'slf4j-log4j12')
        // }
    }
}


  1. eureka.build.gradle
dependencies {
    compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
}

  1. eureka.application.yml
server:
  port: 6868
spring:
  application:
    name: eureka
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      # 浏览器打开: http://localhost:6868/
      defaultZone: http://127.0.0.1:${server.port}/eureka/

项目坐标
https://github.com/HouYuSource/cloud_demo

最后唠叨一下
学习cloud的对电脑的内存有一定要求,
8G最基本,
16G勉勉强强
32G最理想
我之前学习的时候8G(4+4), 昨天闲鱼160入手一个二手三星8G现在的话(4+8),不知道能活多久,哈哈哈…(准备闲鱼出4G内存条,有需要的话可以联系我呀[奸笑]:[email protected])

  • 现在是12G开了3个微服务58%) >>>> 当初学习8G开4个服务就93%
    使用gradle构建spring cloud,搭建一个cloud的helloworld

使用gradle构建spring cloud,搭建一个cloud的helloworld

学习与交流
[email protected]
[email protected]

我的博客
https://shaines.cn

相关文章:

  • 2022-01-09
  • 2021-08-14
  • 2021-05-26
  • 2021-07-05
  • 2021-06-21
  • 2021-09-06
  • 2021-04-01
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2021-07-31
  • 2021-08-20
  • 2022-03-08
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案