4.0.0
com.topcheer
microservicecloud
0.0.1-SNAPSHOT
microservicecloud-zuul-gateway-9527
org.springframework.cloud
spring-cloud-starter-zuul
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.cloud
spring-cloud-starter-config
com.topcheer
microservicecloud-api
${project.version}
org.springframework.boot
spring-boot-starter-jetty
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
创建application.yml配置文件(注意:hosts文件中gateway-9527.com需要添加上)
server:
port: 9527 #设置端口为9527
spring:
application:
name: microservicecloud-zuul-gateway
eureka: #这个就是将8001服务端注册进入注册中心,下面的就是注册中心的注册地址
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
instance:
instance-id: gateway-9527.com
prefer-ip-address: true #访问路径可以显示IP地址
info:
app.name: topcheer-microservicecloud
company.name: com.topcheer
build.artifactId: $project.artifactId$
build.version: $project.version$
测试
a:首先启动3个Eureka集群,再启动一个服务提供类microservicecloud-provider-dept-8001,最后启动刚健的路由微服务
b:效果
c:不使用路由访问8001
d:启用路由访问
地址:http://myzuul.com:9527/microservicecloud-dept/dept/get/1
http://域名反射:路由网关微服务端口/指定提供者微服务名称/提供者微服务接口路径
4.0.0
com.topcheer
microservicecloud
0.0.1-SNAPSHOT
microservicecloud-config-3344
org.springframework.cloud
spring-cloud-config-server
org.eclipse.jgit
org.eclipse.jgit
4.10.0.201712302008-r
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.cloud
spring-cloud-starter-config
org.springframework.boot
spring-boot-starter-jetty
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
⑷创建启动类
⑸修改window下的hosts文件
⑹测试微服务是否可以获取GitHub下的配置文件
a:启动3344微服务
b:读取开发环境信息
c:读取测试环境信息
d:其他访问的路径方式
4.0.0
com.topcheer
microservicecloud
0.0.1-SNAPSHOT
microservicecloud-config-client-3355
org.springframework.cloud
spring-cloud-starter-config
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.boot
spring-boot-starter-jetty
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
创建application.yml文件,注意:名称需要和bootstrap.yml中的一致(microservicecloud-config-client)
测试,启动3344,和3355进行测试
访问地址的组成:
http://IP:从Github上读取指定环境的端口/controller方法路径
GitHub上指定环境的内容:
spring:
profiles:
active:
- dev
---
server:
port: 8001 #设置端口为8001
spring:
profiles: dev #开发环境
application:
name: microservicecloud-config-dept-client
datasource:
type: com.alibaba.druid.pool.DruidDataSource #设置当前数据源
driver-class-name: org.gjt.mm.mysql.Driver #设置mysql驱动包
url: jdbc:mysql://localhost:3306/cloudDB01 #设置数据库名称
username: root
password: 897570
dbcp2:
min-idle: 5 #设置数据库连接池的最小维持连接数
initial-size: 5 #设置初始化链接数
max-total: 5 #设置最大连接数
max-wait-millis: 200 #设置链接获取的最大超时时间
mybatis:
config-location: classpath:mybatis/mybatis.cfg.xml #设置mybatis配置文件所在的路径
type-aliases-package: com.topcheer.springcloud.entities #扫描所有实体类所在包
mapper-locations:
- classpath:mybatis/mapper/**/*.xml #扫描mybatis的映射文件
eureka: #这个就是将8001服务端注册进入注册中心,下面的就是注册中心的注册地址
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/
instance:
instance-id: dept-8001.com
prefer-ip-address: true #访问路径可以显示IP地址
info:
app.name: topcheer-microservicecloud
company.name: com.topcheer
build.artifactId: $project.artifactId$
build.version: $project.version$
---
server:
port: 8001 #设置端口为8001
spring:
profiles: test #开发环境
application:
name: microservicecloud-config-dept-client
datasource:
type: com.alibaba.druid.pool.DruidDataSource #设置当前数据源
driver-class-name: org.gjt.mm.mysql.Driver #设置mysql驱动包
url: jdbc:mysql://localhost:3306/cloudDB02 #设置数据库名称
username: root
password: 897570
dbcp2:
min-idle: 5 #设置数据库连接池的最小维持连接数
initial-size: 5 #设置初始化链接数
max-total: 5 #设置最大连接数
max-wait-millis: 200 #设置链接获取的最大超时时间
mybatis:
config-location: classpath:mybatis/mybatis.cfg.xml #设置mybatis配置文件所在的路径
type-aliases-package: com.topcheer.springcloud.entities #扫描所有实体类所在包
mapper-locations:
- classpath:mybatis/mapper/**/*.xml #扫描mybatis的映射文件
eureka: #这个就是将8001服务端注册进入注册中心,下面的就是注册中心的注册地址
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/
instance:
instance-id: dept-8001.com
prefer-ip-address: true #访问路径可以显示IP地址
info:
app.name: topcheer-microservicecloud
company.name: com.topcheer
build.artifactId: $project.artifactId$
build.version: $project.version$
4.0.0
com.topcheer
microservicecloud
0.0.1-SNAPSHOT
microservicecloud-config-eureka-client-7001
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-starter-eureka-server
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
4.0.0
com.topcheer
microservicecloud
0.0.1-SNAPSHOT
microservicecloud-config-dept-client-8001
org.springframework.cloud
spring-cloud-starter-config
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-eureka
com.topcheer
microservicecloud-api
${project.version}
junit
junit
mysql
mysql-connector-java
com.alibaba
druid
ch.qos.logback
logback-core
org.mybatis.spring.boot
mybatis-spring-boot-starter
org.springframework.boot
spring-boot-starter-jetty
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
文章目录