eureka:配置文件
注解@EnableDiscoveryServer
1 首先加上eurekaserver 的依赖
2 test依赖自动添加
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
provider:
注解@EnableDiscoveryServer
@MaperScan
加入config后
bootstrap.yml文件 (gateway consumer 同下)
#http://localhost:7900/group/provider/dev
spring:
cloud:
config:
uri: http://localhost:7900
name: air #文件前缀
profile: provider #后缀
label: dev #组号

1 测试依赖 自动添加
2 mysql 的依赖
3 eureka 的客户端依赖
4 springweb
5 mybatis 依赖
6 springCloud 依赖(自带)
7 common 依赖 (将common打包)
8 config 依赖
9 bootstrap 依赖(手动添加 要在gitee中拿配置)
3测试依赖 自动添加
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>cn.bdqn</groupId>
<artifactId>group-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
consumer:
注解:
@EnableDiscoveryClient
@EnableFeignClient
Client interface 中的配置
@FeignClient(value = "group-provider" ,fallback = ServiceClientImpl.class)
实现类中加
@Component注解 (通用注解)

1test测试
2openfeign
3eureka 客户端
4config 客户端
5springweb
6common 配置
7 hystrix(手动)
8bootstrap
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>cn.bdqn</groupId>
<artifactId>group-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
gateway:
注解
@EnableDiscoveryClient
@EnableConfigServer
gateway 中的配置文件
server:
port: 8005
spring:
application:
name: group-gateway
cloud:
gateway:
routes:
- id: group-consumer #ID 保持唯一
uri: lb://group-consumer #需要代理映射的应用名称,命名格式lb://应用名
predicates:
- Path=/group/** #映射的路径规则,以api开头的请求都会转发到uri指定的应用去处理
filters:
- StripPrefix=1 #转发请求的时候需要删除的信息。1代表去除第一个参数。
eureka:
client:
service-url:
defaultZone: http://localhost:7776/eureka

1 test
2gateway
3eurekaclient
(如果将gateway的配置也保存到gitee 中 也需要加上 bootstrap 依赖)
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
config:

1test
2eurekaClient
3configServer
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
283




被折叠的 条评论
为什么被折叠?



