• 分布式微服务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
  • 相关阅读:
    springMVC数据绑定入门
    网易云课堂js学习笔记
    Java MyBatis insert数据库数据后返回主键
    (转)关于离职
    mybatis异常:Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for。。。。。。
    tomcat端口号被占用的问题
    tomcat中catalina是什么
    通过代码实现创建、删除、文件的读、写
    HNOI2008玩具装箱 斜率优化
    [ZJOI2008]骑士
  • 原文地址:https://www.cnblogs.com/pzyin/p/12936283.html
Copyright © 2020-2023  润新知