springcloud 踩坑记录(持续更新)
文章目录
- The bean 'xxx', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disable
- feign.FeignException$MethodNotAllowed: status 405 reading
- HystrixTimeoutException
- feign.codec.EncodeException: class java.util.Collections$SingletonMap is not a type supported by this encoder.
本文主要记录学习springcloud遇到的问题及解决方案。
版本:springboot 2.1.6.RELEASE ,springcloud Greenwich.SR1
The bean ‘xxx’, defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disable
1、FeignClientSpecification
Description:
The bean 'ZUUL-GATEWAY.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
2、characterEncodingFilter
Description:
The bean 'characterEncodingFilter', defined in class path resource [zipkin/autoconfigure/ui/ZipkinUiAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
出现原因
1、出现第一个的原因是在一个服务调用其他多个服务,因为都是通过网关调用的,所以@FeignClient(name = “ZUUL-GATEWAY”) 都是这么写的,导致了bean 出现重复
2、第二个是SpringCloud Sleuth 整合zipkin-server出现的问题
这两个都是bean 出现重复
解决方案
如果是在FeignClient中出现的这个问题,在网上说还有一种解决方案就是@FeignClient注解中的contextId只要不一样就行,这样的确是启动不报错,但是在调用的时候会报找不到网关服务。在我使用的这个版本中是这样的。
最终还是按照控制台提示在配置文件中添加
# 允许重名
spring.main.allow-bean-definition-overriding=true
feign.FeignException$MethodNotAllowed: status 405 reading
这个是Feign多参数传递时的问题,可以参考Spring Cloud Feign 多参数传递了解一下?
HystrixTimeoutException
com.netflix.hystrix.exception.HystrixTimeoutException
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1142)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37)
at org.springframework.cloud.sleuth.instrument.async.TraceCallable.call(TraceCallable.java:70)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:1159)
at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Hystrix超时异常
原因
到达了Hystrix 熔断的时间
解决方案
1、设置超时时间
#fackball 时间
hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds=10000
2、禁用超时
# 禁用超时时间
hystrix.command.fallbackcmd.execution.enable=false
feign.codec.EncodeException: class java.util.Collections$SingletonMap is not a type supported by this encoder.
feign.codec.EncodeException: class java.util.Collections$SingletonMap is not a type supported by this encoder.
at feign.codec.Encoder$Default.encode(Encoder.java:94)
at feign.form.FormEncoder.encode(FormEncoder.java:90)
at feign.form.spring.SpringFormEncoder.encode(SpringFormEncoder.java:74)
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:372)
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:224)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:75)
at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:109)
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47)
at org.springframework.cloud.sleuth.instrument.async.TraceCallable.call(TraceCallable.java:70)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
出现原因
在使用feign进行文件上传的时候,消费者调用生产者的文件上传接口时没有限制文件上传类型。
其他情况如果是需要指定类型的话也可能会出现这个问题
解决方案
使用feign调用其他服务时使用consumes 指定媒体类型
@PostMapping(value = "uploadFile" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
String uploadFile(@RequestPart("file") MultipartFile multipartFile);
有兴趣的可以关注一下我的springcloud 专栏
能力一般,水平有限,如有错误,请多指出。
点个关注,给个赞呗