资讯专栏INFORMATION COLUMN

dubbxo开发中遇到的错误总结

jk_v1 / 2448人阅读

摘要:如果是其它方式引发的错误,此处的解决方法不可用。最与该错误重要便是前两个。仔细检查发现,在接口中将参数转化为一个对象,但没有指出该对象就是错误代码根据查询条件查询登录注册访问统计数据解决办法接口中添加相应的注解。

1. object is not an instance of declaring class 错误日日志
 2016-06-01 10:55:59,612 [RMI TCP Connection(127.0.0.1:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x154ff32b10a0058 after 0ms
[01/06/16 10:56:05:005 CST] http-nio-8090-exec-6 DEBUG core.SynchronousDispatcher: PathInfo: /tianji/items/pulloffshelf
2016-06-01 10:56:05,589 [http-nio-8090-exec-6] WARN  cn.company.test.exceptions.RestExceptionMapper - [runtime exception] : %s
2016-06-01 10:56:05,589 [http-nio-8090-exec-6] DEBUG cn.company.test.exceptions.RestExceptionMapper - [runtime exception] :
org.jboss.resteasy.spi.InternalServerErrorException: Bad arguments passed to org.jboss.resteasy.spi.metadata.ResourceMethod@6b9e0ff4  ( cn.company.goods.pojos.PullOffShelves cn.company.goods.pojos.PullOffShelves@2e1cb83d )
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:177) ~[resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:288) ~[resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:242) ~[resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229) ~[resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.7.Final.jar:?]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.7.Final.jar:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:?]
    at com.alibaba.dubbo.rpc.protocol.rest.DubboHttpServer$RestHandler.handle(DubboHttpServer.java:86) [dubbo-2.8.4.jar:2.8.4]
    at com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet.service(DispatcherServlet.java:64) [dubbo-2.8.4.jar:2.8.4]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.35]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.35]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.35]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.35]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.35]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.35]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.35]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.35]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.35]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.35]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.35]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) [catalina.jar:8.0.35]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) [tomcat-coyote.jar:8.0.35]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [tomcat-coyote.jar:8.0.35]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) [tomcat-coyote.jar:8.0.35]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) [tomcat-coyote.jar:8.0.35]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_91]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.35]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) ~[resteasy-jaxrs-3.0.7.Final.jar:?]
    ... 33 more
2016-06-01 10:56:12,950 [RMI TCP Connection(127.0.0.1:2181)] DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x154ff32b10a0058 after 0ms

通篇错误最明显的两个地方:

org.jboss.resteasy.spi.InternalServerErrorException: Bad arguments passed to org.jboss.resteasy.spi.metadata.ResourceMethod@6b9e0ff4 ( cn.company.goods.pojos.PullOffShelves cn.company.goods.pojos.PullOffShelves@2e1cb83dCaused by: java.lang.IllegalArgumentException: object is not an instance of declaring class

错误原因

在dubbox的service(itemServiceImpl)中实现了两个接口(itemervice,itemPullOffShelfService),dubbox暴露给zk的服务(dubbo:service)有两个,但是实现的bean有一个(ref),zk虽然注册了服务,但是rest(暂且当作消费方)调用接口的时候,不知道调用的是哪一个资源接口。

如果是其它方式引发的错误,此处的解决方法不可用。

解决方法

将两个接口合并到同一个接口或者分别实现两个接口。问题即可解决。

2. Could not find message body reader for type 错误日志
[02/06/16 04:34:38:038 CST] http-nio-8080-exec-5  INFO support.LoggingFilter:  [DUBBO] The contents of request body is: 

, dubbo version: 2.8.4, current host: 127.0.0.1
[02/06/16 04:34:38:038 CST] http-nio-8080-exec-5  WARN core.ExceptionHandler: failed to execute
javax.ws.rs.NotSupportedException: Could not find message body reader for type: class cn.company.common.query.BaseSearch of content type: */*
    at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50)
    at com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter.aroundReadFrom(LoggingFilter.java:75)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
    at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:150)
    at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:288)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:242)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at com.alibaba.dubbo.rpc.protocol.rest.DubboHttpServer$RestHandler.handle(DubboHttpServer.java:86)
    at com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet.service(DispatcherServlet.java:64)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
[02/06/16 04:34:38:038 CST] http-nio-8080-exec-5  INFO support.LoggingFilter:  [DUBBO] The HTTP headers are: 
, dubbo version: 2.8.4, current host: 127.0.0.1
错误原因

这是由于在接口实现中没有添加相应的注解:@QueryParam,@BeanParam,@Component,@Consumes,@Produces等注解。最与该错误重要便是前两个。

我的错误指出来了,是不能找到消息体类型,这说明传入的参数出错,或者接口获取参数出错。仔细检查发现,在接口中将request参数转化为一个对象,但没有指出该对象就是@BeanParam.

错误代码:

@Component("loginRegisterService")
@Path("statistics")
@Produces({ContentType.APPLICATION_JSON_UTF_8})
public class LoginRegisterServiceImpl implements LoginRegisterService {
    Log logger = LogFactory.getLog(LoginRegisterServiceImpl.class);

    @Resource
    private LoginRegisterStRepo login;
    /**
     * 根据查询条件查询登录注册访问统计数据
     *
     * @param search
     * @return
     */
    @Override
    @GET
    @Path("login_reg")
    public List getLoginRegSt(final BaseSearch search) {
        this.getDebugInfo();
        return login.getLoginRegsiterSt(search);
    }
}
解决办法

接口中添加相应的注解。

改正后的代码:

@Component("loginRegisterService")
@Path("statistics")
@Produces({ContentType.APPLICATION_JSON_UTF_8})
public class LoginRegisterServiceImpl implements LoginRegisterService {
    Log logger = LogFactory.getLog(LoginRegisterServiceImpl.class);

    @Resource
    private LoginRegisterStRepo login;
    /**
     * 根据查询条件查询登录注册访问统计数据
     *
     * @param search
     * @return
     */
    @Override
    @GET
    @Path("login_reg")
    public List getLoginRegSt(@BeanParam final BaseSearch search) {
        this.getDebugInfo();
        return login.getLoginRegsiterSt(search);
    }
}
3.java.io.EOFException: No content to map to Object due to end of input 错误日志

当请求一个rest服务api时,服务器报错:

java.io.EOFException: No content to map to Object due to end of input
错误原因

对于service的实现,接收参数没有注解为javax.ws.rs.* 类型之一,*包括:BeanParam和QueryParam,至于注解哪一种,需要根据情况而定,如果参数是Bean,用前者,是单个接收参数,用后者。

注意:这种错误出现时整个service没有注解,如果一个service中单个方法没有注解,则会出现#2的情况。

解决办法

加入上述相应的注解。

/**
     * 订单复购率订单数统计数据
     *
     * @param search
     * @return
     */
    @Override
    @GET
    @Path("reorder")
    public List> getReOrder(@BeanParam final BaseSearch search) {
        return null;
    }
4.Due to limitations of the BasicDBObject, you can’t add a second ‘$and’ 错误日志

首先这是一个mongodb的错误,暂且放到这里面。

java.lang.RuntimeException: org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can"t add a second "$and" expression specified as "$and : [ { "time" : { "$gte" : null }}]". Criteria already contains "$and : [ { "appid" : { "$regex" : "fgdarr561puu" , "$options" : "i"}}]".
错误原因

在一个Criteria实例中只能使用一次andOperator方法,而我这里使用了两次,因为appid和mobile都不为空。

if (share.getAppid() != null && StringUtils.isNotEmpty(share.getAppid())) {
                criteria.andOperator(Criteria.where("appid").regex(share.getAppid(), "i"));
if (share.getMobile() != null) {
   criteria.andOperator(Criteria.where("mobile").regex(share.getMobile(), "i"));

如果要使用过个字段的操作,请看mkyong的解决方法:

Problem

Using Spring data and Mongodb, below is a function to find data within a date range.

public List findByIpAndDate(String ip, Date startDate, Date endDate) {

    Query query = new Query(
        Criteria.where("ip").is(ip)
        .andOperator(Criteria.where("createdDate").gte(startDate))
        .andOperator(Criteria.where("createdDate").lt(endDate))
    );
                
    return mongoOperation.find(query, RequestAudit.class);

}

It hits following error message :

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: 
    Due to limitations of the com.mongodb.BasicDBObject, you can"t add a second "$and" 
    expression specified as "$and : [ { "createdDate" : { "$lt" : { "$date" : "2013-02-25T16:00:00.000Z"}}}]". 
    Criteria already contains "$and : [ { "createdDate" : { "$gte" : { "$date" : "2013-02-24T16:00:00.000Z"}}}]"

### Solution
Adding multiple “$and” operators on the same field “createdDate” will make Spring interprets it into a wrong mongodb query. To fix it, change the query to follow :

Query query = new Query(
    Criteria.where("ip").is(ip)
    .andOperator(
        Criteria.where("createdDate").lt(endDate),
        Criteria.where("createdDate").gte(startDate)
    )
);
For multiple criteria on the same field, uses a “comma” to combine them.
解决方法

如果你的需要和mkyong的一样,可以使使用合并字段到andOperator()方法中,当然你可以使用and()方法,由于我这里要对参数过滤,选择使用and()操作。
扩展:类似的错误经常在我们判断的时间字段上,比如我们需要做开始时间和结束时间范围内的操作,此时我们是不是要判断开始时间和结束时间,如下:。

if (share.getStart() != null && share.getStart() != 0) {
    criteria.and("time").lt(share.getEnd());
}
if (share.getEnd() != null && share.getEnd() != 0) {
    criteria.and("time").gte(share.getStart());
}

这段代码也会报错,Criteria不允许同一字段多次出现在操作(and,andOperator,etc)中。
修改上述逻辑:

if (share.getStart() != null && share.getStart() != 0 && share.getEnd() != null && share.getEnd() != 0) {
    criteria.and("time").gte(share.getStart()).lt(share.getEnd());
} else if (share.getStart() != null && share.getStart() != 0 && (share.getEnd() == null || share.getEnd() == 0)) {
    criteria.and("time").lt(share.getEnd());
} else if ((share.getStart() == null || share.getStart() == 0) && share.getEnd() != null && share.getEnd() != 0) {
    criteria.and("time").gte(share.getStart());
}
6. java.net.SocketTimeoutException: connect timed out 错误日志
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=10.132.0.169:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
错误原因

出现这类情况,大概有以下几种情况:

mongo地址开启了bind_ip

操作系统开启了防火墙,shell可以连接,但是java程序不能连接

程序连接配置错误,比如ip,port

程序本身写法错误

解决办法

如果开启了bind_ip,请加入你的服务器ip地址到该配置,或者,如果没有必要的时候,配置成0.0.0.0,这样任意机器均可访问

具体请看这里:centos7防火墙导致java程序访问mongodb3.0.1时报错的问题

配置mongo的连接,仔细检查ip、port的配置,有时候会把169写成196类似的错误

程序错误,请修改bug在连接

7.Unable to create a Configuration, because no Bean Validation provider could be found. 错误日志
2016-08-15 13:54:30,369 [ConsumeMessageThread_1] WARN  cn.joyven.kuaidi.mq.consumer.ImportShipHandler - Failed to invoke the method ship in the service cn.joyven.test.api.OrderService. Tried 3 times of the providers [192.168.2.245:8091] (1/1) from the registry 127.0.0.1:2181 on the consumer 192.168.2.47 using the dubbo version 2.8.4. Last error is: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
错误原因

未知

解决办法

在stackover上看到了一个解决方案:http://stackoverflow.com/ques...
这里给出一个此类问题的确认方法:
在dubbo的xml配置中,直接使url配置直接访问dubbo服务,看是否能够正常使用,如果能够正常使用,则说明就是验证器的问题引起的。
一般情况我们是通过zk去注册中心订阅服务的,不需要url配置,但为了定位问题,如下配置(增加url配置):

gradle项目:在gradle.build中增加

compile "org.hibernate:hibernate-validator:5.2.0.Final"

maven项目:在pom.xml中增加


    org.hibernate
    hibernate-validator
    5.2.0.Final

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/66007.html

相关文章

  • 从一次重写原生方法遇到坑,总结一下Web事件系统

    摘要:问题初探索删掉那一点重写的代码后,表现符合预期了。每一次都重新造一个虚拟的,然后监听其自定义事件,并且立即触发这个自定义事件。真的不要随便重写原生方法。。。于是,我全面总结一下了中的事件系统,也算是对基础的巩固。 写在前面 前段时间,我写过一篇文章前端开发中的Error以及异常捕获。 在文章中,我提到了这个问题: showImg(https://segmentfault.com/img...

    oysun 评论0 收藏0
  • 微信小程序项目总结(一)

    摘要:前言微信小程序的开发,我应该算是赶上了第一波,所以,自然是一路踩坑而来。注以下标题是按照微信开发工具上的选项进行划分的。不过,除此之外,它还会产生另外一个副作用,就是可能连小程序本身上的请求都请求不了了。 -- KChris 2017.3.16 (=^.^=) 前言微信小程序的开发,我应该算是赶上了第一波,所以,自然是一路踩坑而来 =。=一月九日,小程序正式上线,早早地就到公司开始改b...

    whatsns 评论0 收藏0
  • 开发十年,我总结出了这些开发经验

    摘要:本文由云社区发表在一线做了十年的开发,经历了网易百度腾讯研究院等几个地方,陆续做过游戏页游浏览器移动端翻译等。四既要有攻城之力,也要有熬战之气产品开发完成后,必然有。功能开发完成后,就要开始守城了。 本文由云+社区发表 在一线做了十年的开发,经历了网易、百度、腾讯研究院、MIG 等几个地方,陆续做过 3D 游戏、2D 页游、浏览器、移动端翻译 app 等。 积累了一些感悟。必然有依然幼...

    warmcheng 评论0 收藏0

发表评论

0条评论

jk_v1

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<