• Nacos01 Spring cloud 服务配置与调用(postgresql & spring cloud)


    前提 serviceA 调用 serviceB

    配置

    <-- 父工程引入-->
    <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.alibaba.cloud</groupId>
                    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                    <version>2.2.0.RELEASE</version>
                </dependency>
            </dependencies>
    </dependencyManagement>
    
    <-- serviceB -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
                <version>2.2.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>2.2.0.RELEASE</version>
            </dependency>
    <-- serviceA  按理说子工程不需要版本号,估计是父工程的版本不支持? 后续有时间再调查-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
                <version>2.2.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>2.2.0.RELEASE</version>
            </dependency>
          <-- openfeign-->
          <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>
    

    seriviceA Application

    @EnableFeignClients
    @EnableDiscoveryClient
    @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) // 不需要数据库
    

    serviceB Applicaiton

    @EnableDiscoveryClient
    @SpringBootApplication
    

    serviceA bootstrap.yml

    spring:
      application:
        name: service-A
      cloud:
        nacos:
          discovery:
            server-addr: http://xxx.xxx.xxx.xx:8848
    server:
      port: 7294
    management:
      endpoints:
        web:
          exposure:
            include: '*'
    

    serviceB bootstrap.yml

    spring:
      application:
        name: service-B
      cloud:
        nacos:
          discovery:
            server-addr: http://xxx.xxx.xxx.xx:8848
          config:
            server-addr: http://xxx.xxx.xxx.xx:8848
            file-extension: yaml
    server:
      port: 7293
    management:
      endpoints:
        web:
          exposure:
            include: '*'
    ~~~yml
    ### serviceB application.yml
    ~~~yml
    spring:
        profiles:
          active: dev
    

    nacos 配置 serviceB 配置信息service-B-dev.yaml

    spring:
      datasource:
        name: pg
        url: jdbc:postgresql://xxx.xxx.xxx.xx/postgres
        username: 
        password: 
        # 使用druid数据源
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: org.postgresql.Driver
    mybatis-plus: # 以下均可删除,是mybatis-plus 的一些配置
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个是打印sql日志的,可以删除
      type-handlers-package: com.xxx.xxx.typehandlers # 这个是类型转换需要的,可以删除
      global-config: # 这些是配置全局默认值的,可以删除
        db-config:
          logic-delete-field: deleteStatus
          logic-delete-value: 1
          logic-not-delete-value: 0
    ~~~yaml
    通过知识/经验的分享,节省开发者的时间.
  • 相关阅读:
    栈区,堆区,全局区,文字常量区,程序代码区 详解
    2010年IT行业十大收购
    三大数据备份方式:完全备份、增量备份以及差异备
    Driver Development Part 1: Introduction to Drivers (code project)
    手工构造典型PE文件(转)
    访问IIS元数据库失败[转]
    代码注入的三种方法(转)
    对象的初始化(转)
    网络和黑客编程基本知识 (转)
    破解linux中root密码(图) 转自csdn
  • 原文地址:https://www.cnblogs.com/ysloong/p/15551372.html
Copyright © 2020-2023  润新知