zoukankan      html  css  js  c++  java
  • 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
    通过知识/经验的分享,节省开发者的时间.
  • 相关阅读:
    ini_set /ini_get函数功能-----PHP
    【转】那个什么都懂的家伙
    word 2007为不同页插入不同页眉页脚
    August 26th 2017 Week 34th Saturday
    【2017-11-08】Linux与openCV:opencv版本查看及库文件位置等
    August 25th 2017 Week 34th Friday
    August 24th 2017 Week 34th Thursday
    August 23rd 2017 Week 34th Wednesday
    August 22nd 2017 Week 34th Tuesday
    August 21st 2017 Week 34th Monday
  • 原文地址:https://www.cnblogs.com/ysloong/p/15551372.html
Copyright © 2011-2022 走看看