1.#SpringBoot整合Mybatis配置 SpringBoot整合Mybatis
mybatis:
#定义别名包: 实现对象映射
type-aliases-package: com.jt.pojo
#加载映射文件一个接口对应一个映射文件
mapper-locations: classpath:/mybatis/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
 
 
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
#如果数据库密码以数字0开头 则必须使用""号包裹
#password: "01234"
 
 
#不打印日志
debug: false
===============================================
2 #SpringBoot整合MP
mybatis-plus:
type-aliases-package: com.jt.pojo
#mapper-locations: classpath*:/*.xml 强制加载全部
mapper-locations: classpath:/mybatis/*.xml
configuration:
map-underscore-to-camel-case: true
 
 
# Mapper接口执行 打印Sql日志
logging:
level:
com.jt.mapper: debug
 
 
server:
port: 8090
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
===============================================
服务方
server:
   port: 8090
 spring:
   application:
     name: sca-consumer
   cloud:
     nacos:
       discovery:
         server-addr: localhost:8848
     sentinel:
       transport:
          dashboard: localhost:8180
         # port: 8719
       web-context-unify: false #取消链路聚合,否则sentinel1.7.2以后会默认将所有链路聚合到一个入口上
 #feign方式的服务熔断处理
 feign:
   hystrix: #hystrix 含义是熔断(就相当于服务停止了)或降级
     enabled: true# 打开springboot工程中的监控端点
 management:
   endpoints:
     web:
       exposure:
         include: '*'
  ===============================================
网关的配置:
server:
   port: 9000
 spring:
   application:
     name: sca-gateway
   cloud:
     nacos:
       discovery:
         server-addr: localhost:8848
     sentinel:
       transport:
         dashboard: localhost:8180
         #port: 8719
       eager: true  #服务启动时会会向sentinel控制台发送心跳,为我们的应用创建菜单
     gateway:  # API Gateway (负责API管理)
       discovery:
         locator:
           enabled: true  #开启基于服务名获取服务实例的功能(基于服务名创建路由)
       routes: #网关路由配置
          - id: router01  #http://localhost:9000/nacos/provider/echo/hello
            #uri: http://localhost:8081
            uri: lb://sca-provider  #lb表示负载均衡,底层默认使用ribbon实现
            predicates: #定义请求规则(请求需要按照此规则设计)
              - Path=/nacos/provider/echo/** #请求路径设计
              #- After=2021-08-23T13:59:59.789+08:00[Asia/Shanghai]
              #- Header=X-Request-Id, \d+  #\d+表示任何一个数字
              #- Method=GET
              #- Query=pageSize,\d+
            filters:
              - StripPrefix=1 #转发之前去掉path中第一层路径,例如nacos
              #- AddRequestHeader=X-Request-Foo, Bar
              #- AddRequestParameter=foo, hello#自己定义白名单路径
 white:
   prefix: /nacos # 假如希望调整负载均衡算法,可参考如下配置方式
 sca-provider: #这个名字为指定的服务名
   ribbon:
     #NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule
     NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
  ===============================================
服务提供方
server:
   port: 8083
 #  tomcat:   #ThreadPoolExecutor
 #    threads:
 #      max: 300
 spring:
   application:
     name: sca-provider
   cloud:
     nacos:
       discovery: #注册中心
         server-addr: localhost:8848
       config: #配置中心的配置
         server-addr: localhost:8848
         file-extension: yml
         namespace: 56638dcc-ac08-4cf6-8043-8b3fbcb21adf #dev
         #group: DEV_GROUP_51
         shared-configs[0]: #共享配置,0表示一个数组下标
           data-id: app-common-dev.yml
           #group: DEFAULT_GROUP
           refresh: true #默认false# 配置日志(经常变化的数据一般会写到配置中心)
 logging:
   level:
     com.jt: error===============================================
认证模块
#port
 #name
 #cloud
 server:
   port: 8071
 spring:
   application:
     name: sca-auth
   cloud:
     nacos:
       discovery:
         server-addr: localhost:8848
       config:
         server-addr: localhost:8848===============================================
网关的配置
server:
   port: 9000
 spring:
   application:
     name: sca-resource-gateway
   cloud:
     nacos:
       discovery:
         server-addr: localhost:8848
       config:
         server-addr: localhost:8848
         file-extension: yml
     gateway:
       discovery:
         locator:
           enabled: true
       routes:
         - id: router01
           uri: lb://sca-resource
           predicates:
             - Path=/sca/resource/upload/**
           filters:
             - StripPrefix=1
         - id: router02
           uri: lb://sca-auth
           predicates:
             #- Path=/auth/login/**  #没要令牌之前
             - Path=/auth/oauth/**   #微服务架构下,需要令牌
           filters:
             - StripPrefix=1
       globalcors: #跨域配置
         corsConfigurations:
           '[/**]':
             allowedOrigins: "*"
             allowedHeaders: "*"
             allowedMethods: "*"
             allowCredentials: true
     sentinel: #限流设计
       transport:
         dashboard: localhost:8180
       eager: true===============================================
资源服务器的配置
server:
   port: 8881
 spring:
   application:
     name: sca-resource
   cloud:
     nacos:
       config:
         server-addr: localhost:8848
         file-extension: yml
       discovery:
         server-addr: localhost:8848
   resources:  #配置静态资源存储位置(默认resources/static目录),现在写到了配置中心
     static-locations: file:d:/uploads#    sentinel:
 #      eager: true  #服务启动时就要与sentinel通讯,在sentinel控制台创建服务菜单
 #      transport:
 #        dashboard: localhost:8180
 #        port: 8719#自定义上传的资源地址和服务器地址(写到了配置中心)
 jt:
   resource:
       path: d:/uploads/
       host: http://localhost:8881/#logging:
 #  level:
 #    com.jt: debug
  ===============================================
系统数据层
server:
   port: 8061
 spring:
   application:
     name: sca-system
   cloud:
     nacos:
       discovery:
         server-addr: localhost:8848
       config:
         server-addr: localhost:8848
         file-extension: yml
   datasource:
     url: jdbc:mysql:///jt-sso?serverTimezone=Asia/Shanghai&characterEncoding=utf8
     username: root
     password: root===============================================
Ridis集群的配置
spring:
   redis:
     cluster: #redis 集群配置
       nodes: 192.168.126.130:8010,192.168.126.130:8011,192.168.126.130:8012,192.168.126.130:8013,192.168.126.130:8014,192.168.126.130:8015
       max-redirects: 3 #最大跳转次数
     timeout: 5000 #超时时间
     database: 0
     jedis: #连接池
       pool:
         max-idle: 8
         max-wait: 0===============================================
eureka  的配置
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka, http://eureka2:2002/eureka
# 向注册中心注册的名称
spring:
application:
name: item-service
------------------------------------------------------------------
spring:
   application:
     name: eureka-server
 # 8001  8101  8201
 # 2001  3001  4001  5001  6001
 server:
   port: 2001
 eureka:
   server:
     # 禁用自我保护模式
     enable-self-preservation: false
   instance:
     # 主机名
     hostname: eureka1
   client:
     # 针对单台服务器,不向自己注册,不从自己拉取
     register-with-eureka: false
     fetch-registry: false---------------------------
# application-eureka2.yml
 eureka:
   instance:
     # 主机名
     hostname: eureka2
   client:
     # 集群服务器之间互相注册、互相拉取
     register-with-eureka: true
     fetch-registry: true
     service-url:
       defaultZone: http://eureka1:2001/eureka===============================================# 自定义的配置属性
# 三个测试用的用户数据, Demo数据: 7,8,9
sp:
user-service:
users: "[{\"id\":7, \"username\":\"abc\",\"password\":\"123\"},
{\"id\":8, \"username\":\"def\",\"password\":\"456\"},
{\"id\":9, \"username\":\"ghi\",\"password\":\"789\"}]"
===============================================# 配置 Ribbon 重试次数
#ribbon:
# MaxAutoRetries: 1
# MaxAutoRetriesNextServer: 2
===============================================
Zuul的配置
zuul:
routes:
item-service: /item-service/**
user-service: /user-service/**
order-service: /order-service/**
===============================================
#    ribbon启用重试配置
   retryable: true
 #
 #ribbon重试配置格式(通用配置)
 #ribbon:
 #  MaxAutoRetries: 0
 #  MaxAutoRetriesNextServer: 1
 #对item-service:(针对某个组件/业务层的)
 #item-service:
 #  ribbon;
 #  MaxAutoRetries: 0
 #  MaxAutoRetriesNextServer: 1===============================================
#hystrix监控日志
 management:
   endpoints:
     web:
       exposure:
         include: "*"===============================================
hystrix dashboard  仪表盘参数(完全独立的项目)在界面上填写监控路径
 hystrix:
   dashboard:
     # 允许抓取的服务器列表
     proxy-stream-allow-list: localhost