远程配置案例测试
作者:互联网
新建一个springcloud-config-eureka-7001模块,导入config依赖
bootstrap.yml和application.yml配置:
将eureka-7001 yml配置拷贝一份config-eureka
1 spring: 2 profiles: 3 active: dev 4 5 --- 6 server: 7 port: 7001 8 9 # spring配置 10 spring: 11 profiles: dev 12 application: 13 name: springcloud-config-eureka 14 15 # Eureka配置 16 eureka: 17 instance: 18 hostname: eureka7001.com #Eureka服务端的实例名称 19 client: 20 register-with-eureka: false #表示是否向Eureka注册中心注册自己 21 fetch-registry: false #fetch-registry若为false,表示自己为注册中心, 22 service-url: 23 # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 24 defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ 25 26 --- 27 28 server: 29 port: 7001 30 31 # spring配置 32 spring: 33 profiles: test 34 application: 35 name: springcloud-config-eureka 36 37 # Eureka配置 38 eureka: 39 instance: 40 hostname: eureka7001.com #Eureka服务端的实例名称 41 client: 42 register-with-eureka: false #表示是否向Eureka注册中心注册自己 43 fetch-registry: false #fetch-registry若为false,表示自己为注册中心, 44 service-url: 45 # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 46 defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/View Code
将config-eureka, git push到远程仓库:
测试config 服务端与远程仓库是否连接成功:
开启springcloud-config-eureka-7001,测试http://localhost:7001/是否正常访问。
新建一个springcloud-config-dept-8001模块,导入config依赖
bootstrap.yml 和 application.yml配置
将springcloud-provider-dept-8001 yml配置拷贝一份config-dept
1 spring: 2 profiles: 3 active: dev 4 --- 5 server: 6 port: 8001 7 8 # mybatis配置 9 mybatis: 10 type-aliases-package: com.company.springcloud.pojo 11 config-location: classpath:mybatis/mybatis-config.xml 12 mapper-locations: classpath:mybatis/mapper/*.xml 13 14 15 # spring的配置 16 spring: 17 profiles: dev 18 application: 19 name: springcloud-config-dept 20 datasource: 21 type: com.alibaba.druid.pool.DruidDataSource #数据源 22 driver-class-name: com.mysql.cj.jdbc.Driver 23 url: jdbc:mysql://localhost:3306/db01?useUnicode=true&characterEncoding=utf-8 24 username: root 25 password: 123456 26 27 #Eureka的配置,服务注册到哪里 28 eureka: 29 client: 30 service-url: 31 defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ 32 instance: 33 instance-id: springcloud-provider-dept-8001 #修改Eureka上默认的描述信息 34 # prefer-ip-address: true 35 36 37 #info配置 38 management: 39 # 开启info端点 40 endpoints: 41 web: 42 discovery: 43 enabled: true 44 exposure: 45 include: "info" 46 # 将info开启 47 info: 48 env: #查看 application.yaml 配置的环境配置信息 开启 49 enabled: true 50 51 info: 52 app.name: springcloud-service-news 53 company.name: www.mark.com 54 --- 55 56 57 server: 58 port: 8001 59 60 # mybatis配置 61 mybatis: 62 type-aliases-package: com.company.springcloud.pojo 63 config-location: classpath:mybatis/mybatis-config.xml 64 mapper-locations: classpath:mybatis/mapper/*.xml 65 66 67 # spring的配置 68 spring: 69 profiles: test 70 application: 71 name: springcloud-config-dept 72 datasource: 73 type: com.alibaba.druid.pool.DruidDataSource #数据源 74 driver-class-name: com.mysql.cj.jdbc.Driver 75 url: jdbc:mysql://localhost:3306/db02?useUnicode=true&characterEncoding=utf-8 76 username: root 77 password: 123456 78 79 #Eureka的配置,服务注册到哪里 80 eureka: 81 client: 82 service-url: 83 defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ 84 instance: 85 instance-id: springcloud-provider-dept-8001 #修改Eureka上默认的描述信息 86 # prefer-ip-address: true 87 88 89 #info配置 90 management: 91 # 开启info端点 92 endpoints: 93 web: 94 discovery: 95 enabled: true 96 exposure: 97 include: "info" 98 # 将info开启 99 info: 100 env: #查看 application.yaml 配置的环境配置信息 开启 101 enabled: true 102 103 info: 104 app.name: springcloud-service-news 105 company.name: www.mark.comView Code
测试config 服务端与远程仓库是否连接成功:
测试7001端口:服务是否注册
测试注册服务8001是否可用:
标签:info,http,com,eureka,案例,测试,springcloud,config,远程 来源: https://www.cnblogs.com/doremi429/p/16629255.html