栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springcloud分布式事务解决(springcloud是分布式框架吗)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springcloud分布式事务解决(springcloud是分布式框架吗)

1 添加依赖


    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
    
        org.springframework.cloud
        spring-cloud-config-server
    
    
    
        org.springframework.cloud
        spring-cloud-starter-netflix-eureka-client
    

2 添加配置

server:
  port: 12000
eureka:
  client:
    service-url:
      defaultZone: http://admin:1234@localhost:7001/eureka/
    fetch-registry: true
    register-with-eureka: true

spring:
  application:
    name: hello-config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/dp147258/hello-sc-2109a.git
          search-paths: config
      label: master

3.添加启动类

@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer

4.在provider(服务提供者添加依赖)


    org.springframework.cloud
    spring-cloud-config-client

5.在provider(服务提供者)创建bootstrap.yml配置文件 删除appplication.yml里面配置(保留info跟logging日志)

bootstrap

server:
  port: 9999

spring:
  application:
    name: hello-provider
  jackson:
    date-format: yyyy-MM-dd
    time-zone: GMT+8

  cloud:
    config:
      discovery:
        enabled: true  #开启配置服务发现
        service-id: hello-config #配置中心服务名称
      label: master  #分支名称
      profile: dev #环境名称
eureka:
  client:
    service-url:
      defaultZone: http://admin:1234@localhost:7001/eureka/,http://admin:1234@localhost:7002/eureka/
    register-with-eureka: true
    fetch-registry: false
  instance:
    instance-id: ${spring.application.name}-${server.port}
    prefer-ip-address: true
    status-page-url-path: /actuator/info
    health-check-url-path: /actuator/health

5.创建目录(方便区分)跟项目同名 gitBatch

创建文件夹config定义两个.yml文件(因在bootstrap跟application里面已无数据源)

在刚定义的.yml文件里面配置数据源

spring:
  datasource:
    username: root
    password: 1234
    url: jdbc:mysql:///db2109

创建文件 (方便上传)

在码云里面创建添加仓库(跟项目同名) ->开源

git init 初始化

git add . 添加暂存区

git commint . -m """" 提交到版本库

执行码云里面最后两行代码

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/773462.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号