分布式微服务SpringCloud 、Dubbo常见异常汇总
(1)java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0
在请求Facade 或是其他 interface时,@RequestParam("phone") String phone,这个参数一定要必填,不可省略。
(2)Consider defining a bean of type 'redis.RedisUtil'
需要在该项目的启动类中进行全表扫描注入 (basePackages = "com.ballon.wonmore.*")
(3)Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `boolean` out of START_OBJECT token
这种一般是返回值有问题,返回值对不上 或是 多层封装了,程序不能自动识别,比如说 ResultMessage套用ResultMessage
(4)feign.codec.EncodeException: No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate.
@RequestMapping(value = "/isInvalidToken", method = RequestMethod.GET, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public boolean isInvalidToken(@RequestParam("token") String token) {
return authService.isInvalidToken(token);
}
(5)Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client
(6)feign.codec.DecodeException: No qualifying bean of type 'org.springframework
解决方案:将feignHttpMessageConverter 进行Decoder
@Configuration public class FeignConfig { @Bean Logger.Level feignLoggerLevel() { return Logger.Level.FULL; } @Bean public Decoder feignDecoder() { return new ResponseEntityDecoder(new SpringDecoder(feignHttpMessageConverter())); } public ObjectFactory<HttpMessageConverters> feignHttpMessageConverter() { final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(new PhpMappingJackson2HttpMessageConverter()); return new ObjectFactory<HttpMessageConverters>() { @Override public HttpMessageConverters getObject() throws BeansException { return httpMessageConverters; } }; } public class PhpMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter { PhpMappingJackson2HttpMessageConverter(){ List<MediaType> mediaTypes = new ArrayList<>(); mediaTypes.add(MediaType.valueOf(MediaType.TEXT_HTML_VALUE + ";charset=UTF-8")); //关键 setSupportedMediaTypes(mediaTypes); } } }
(7)org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'null' in
这种异常一般来说是因为客户端服务器漏写了注解 比如 @RequestBody
(8)Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
方案一 (解决原因1)
排除此类的autoconfig。启动以后就可以正常运行。
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
方案二 (解决原因2)
在application.properties/或者application.yml文件中没有添加数据库配置信息.
(9)允许bean 重复定义
spring.main.allow-bean-definition-overriding=true