java-springcloud实战bug

springcloud项目搭建过程中碰到的bug

遇到的最多的错误:

1. 无法连接

1
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
  1. 服务端未启动,此时启动调用服务端服务的工程就会出现这一错误
  2. eureka未启动,启动注册了eureka的服务端也会出现

2. 网关异常

1
2
3
4
5
6
7

Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

解决方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
可能是加了这个spring-cloud-starter-netflix-eureka-server依赖 ,比如
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>

改成依赖spring-cloud-starter-netflix-eureka-client,比如

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

image-20220107134708198

此时实现了正确的网关注册

3. 服务的启动顺序

  1. eureka-serve

    只要微服务进行了注册,就必须先打开eureka,作为一个管理容器

  2. user-service

    被调用服务,这个不打开,调用了也白搭

  3. getway网关服务