接下来我们把Eureka7001和Dept8001的配置文件放到git上面远程获取一下试试:
1.新建文件config-eureka.yml和config-dept.yml并上传到git远程仓库。
spring: profiles: active: dev --- server: port: 7001 #spring的配置 spring: profiles: dev application: name: springcloud-config-eureka #Eureka配置 eureka: instance: hostname: localhost7001 #Eureka服务端的实例名称 client: register-with-eureka: false #表示是否向eureka注册中心注册自己 fetch-registry: false #fetch-registry如果false,则表示自己为注册中心 service-url: #监控页面 defaultZone: http://localhost:7002/eureka/,http://localhost:7003/eureka/ --- server: port: 7001 #spring的配置 spring: profiles: test application: name: springcloud-config-eureka #Eureka配置 eureka: instance: hostname: localhost7001 #Eureka服务端的实例名称 client: register-with-eureka: false #表示是否向eureka注册中心注册自己 fetch-registry: false #fetch-registry如果false,则表示自己为注册中心 service-url: #监控页面 defaultZone: http://localhost:7002/eureka/,http://localhost:7003/eureka/
spring: profiles: active: dev --- server: port: 8001 #mybatis配置 mybatis: type-aliases-package: com.allen.springcloud.pojo config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml #spring配置 spring: profiles: dev application: name: springcloud-config-dept datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://123456789:3306/db01?useUnicode=true&serverTimezone=GMT%2B8&useSSL=false username: 123456789 password: 123456789 #Eureka的配置 eureka: client: service-url: defaultZone: http://localhost:7001/eureka/,http://localhost:7002/eureka/,http://localhost:7003/eureka/ instance: instance-id: springcloud-provider-dept8001 #修改eureka上的默认描述信息 prefer-ip-address: true #true,可以显示服务的ip地址 #info配置 info: app.name: allenSpringCloud --- server: port: 8001 #mybatis配置 mybatis: type-aliases-package: com.allen.springcloud.pojo config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml #spring配置 spring: profiles: test application: name: springcloud-config-dept datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://123456789:3306/db01?useUnicode=true&serverTimezone=GMT%2B8&useSSL=false username: 123456789 password: 123456789 #Eureka的配置 eureka: client: service-url: defaultZone: http://localhost:7001/eureka/,http://localhost:7002/eureka/,http://localhost:7003/eureka/ instance: instance-id: springcloud-provider-dept8001 #修改eureka上的默认描述信息 prefer-ip-address: true #true,可以显示服务的ip地址 #info配置 info: app.name: allenSpringCloud
3.新建springcloud-config-eureka-7001项目,并复制依赖和添加config的依赖。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud</artifactId> <groupId>com.allen</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-config-eureka-7001</artifactId> <dependencies> <!-- config --> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-config --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> <version>2.1.1.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>2.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> </project>
4.新建配置文件bootstrap.yml和application.xml。
spring: cloud: config: name: config-eureka label: master profile: dev uri: http://localhost:3344
spring: application: name: springcloud-config-eureka-7001
5.把启动类也复制过来。
6.启动3344和7001进行测试。
7001正常访问:
7.安装上面同样的步骤,新建springcloud-config-dept-8001。
8.启动测试。
进入localhost:7001看看服务有没有被注册进来:
服务已经被注册进来了没有问题,接下来我们调用接口测试一下:
接口调用成功也没有问题,接下来我们远程修改配置文件,让他调用db02数据库里面的内容:
重启项目或者热部署之后测试:
成功远程修改配置文件,更改数据库连接。