SpringCloud开发中遇到问题总结

1:Feign PathVariable annotation was empty on param 0.

 

  使用Feign的时候,在service中如果参数中带有

@PathVariable,@RequestParam形式的参数,则要用value=""标明对应的参数,否则会抛出IllegalStateException异常,
其中value的值应该和后面的参数名一样,否则会出现这样的异常:

Illegal character in path at index 25: http://user-service/user/{id}

2:配置 启动 Hystrix Dashboard 报错

项目中包好eureka-server,user-service,hystrix-service,hystrix-dashboard.

除了在hystrix-dashboard中添加

org.springframework.boot:spring-boot-starter-actuator

还要在hystrix-service里添加。

并且在hystrix-service中启动类中添加:

@Bean
public ServletRegistrationBean getServlet(){
    HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/actuator/hystrix.stream");
    registrationBean.setName("HystrixMetricsStreamServlet");
    return registrationBean;
}

这样就可以了。还有需要在hystrix-service的配置文件中添加:

#暴露hystrix监控端点
management.endpoints.web.exposure.include=*

3:spring Cloud config下的client服务中的配置文件不能像其他一样用application.properties文件,名称要改为bootstrap.properties.(由于之前都是用application的较多,容易出现错误。)

4:在springCloud的gateway网关的开发中遇到这样的异常:

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.

 

因为spring cloud gateway是基于webflux的,如果非要web支持的话需要导入spring-boot-starter-webflux而不是spring-boot-start-web。所以需要改成如下:

dependencies {
   // compile('org.springframework.cloud:spring-cloud-starter-gateway')
    implementation("org.springframework.cloud:spring-cloud-starter-gateway") {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web'
    }

}

这样启动就正常了。
 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值