摘要:如果是其它方式引發(fā)的錯誤,此處的解決方法不可用。最與該錯誤重要便是前兩個。仔細檢查發(fā)現(xiàn),在接口中將參數(shù)轉(zhuǎn)化為一個對象,但沒有指出該對象就是錯誤代碼根據(jù)查詢條件查詢登錄注冊訪問統(tǒng)計數(shù)據(jù)解決辦法接口中添加相應的注解。
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@2e1cb83d和Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class。
錯誤原因在dubbox的service(itemServiceImpl)中實現(xiàn)了兩個接口(itemervice,itemPullOffShelfService),dubbox暴露給zk的服務(dubbo:service)有兩個,但是實現(xiàn)的bean有一個(ref),zk雖然注冊了服務,但是rest(暫且當作消費方)調(diào)用接口的時候,不知道調(diào)用的是哪一個資源接口。
如果是其它方式引發(fā)的錯誤,此處的解決方法不可用。
解決方法將兩個接口合并到同一個接口或者分別實現(xiàn)兩個接口。問題即可解決。
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錯誤原因
這是由于在接口實現(xiàn)中沒有添加相應的注解:@QueryParam,@BeanParam,@Component,@Consumes,@Produces等注解。最與該錯誤重要便是前兩個。
我的錯誤指出來了,是不能找到消息體類型,這說明傳入的參數(shù)出錯,或者接口獲取參數(shù)出錯。仔細檢查發(fā)現(xiàn),在接口中將request參數(shù)轉(zhuǎn)化為一個對象,但沒有指出該對象就是@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; /** * 根據(jù)查詢條件查詢登錄注冊訪問統(tǒng)計數(shù)據(jù) * * @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; /** * 根據(jù)查詢條件查詢登錄注冊訪問統(tǒng)計數(shù)據(jù) * * @param search * @return */ @Override @GET @Path("login_reg") public List3.java.io.EOFException: No content to map to Object due to end of input 錯誤日志getLoginRegSt(@BeanParam final BaseSearch search) { this.getDebugInfo(); return login.getLoginRegsiterSt(search); } }
當請求一個rest服務api時,服務器報錯:
java.io.EOFException: No content to map to Object due to end of input錯誤原因
對于service的實現(xiàn),接收參數(shù)沒有注解為javax.ws.rs.*?類型之一,*包括:BeanParam和QueryParam,至于注解哪一種,需要根據(jù)情況而定,如果參數(shù)是Bean,用前者,是單個接收參數(shù),用后者。
注意:這種錯誤出現(xiàn)時整個service沒有注解,如果一個service中單個方法沒有注解,則會出現(xiàn)#2的情況。
解決辦法加入上述相應的注解。
/** * 訂單復購率訂單數(shù)統(tǒng)計數(shù)據(jù) * * @param search * @return */ @Override @GET @Path("reorder") public List4.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 ListfindByIpAndDate(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()方法,由于我這里要對參數(shù)過濾,選擇使用and()操作。
擴展:類似的錯誤經(jīng)常在我們判斷的時間字段上,比如我們需要做開始時間和結束時間范圍內(nèi)的操作,此時我們是不是要判斷開始時間和結束時間,如下:。
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不允許同一字段多次出現(xiàn)在操作(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}}]錯誤原因
出現(xiàn)這類情況,大概有以下幾種情況:
mongo地址開啟了bind_ip
操作系統(tǒng)開啟了防火墻,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
文章版權歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/66007.html
摘要:問題初探索刪掉那一點重寫的代碼后,表現(xiàn)符合預期了。每一次都重新造一個虛擬的,然后監(jiān)聽其自定義事件,并且立即觸發(fā)這個自定義事件。真的不要隨便重寫原生方法。。。于是,我全面總結一下了中的事件系統(tǒng),也算是對基礎的鞏固。 寫在前面 前段時間,我寫過一篇文章前端開發(fā)中的Error以及異常捕獲。 在文章中,我提到了這個問題: showImg(https://segmentfault.com/img...
摘要:前言微信小程序的開發(fā),我應該算是趕上了第一波,所以,自然是一路踩坑而來。注以下標題是按照微信開發(fā)工具上的選項進行劃分的。不過,除此之外,它還會產(chǎn)生另外一個副作用,就是可能連小程序本身上的請求都請求不了了。 -- KChris 2017.3.16 (=^.^=) 前言微信小程序的開發(fā),我應該算是趕上了第一波,所以,自然是一路踩坑而來 =。=一月九日,小程序正式上線,早早地就到公司開始改b...
摘要:本文由云社區(qū)發(fā)表在一線做了十年的開發(fā),經(jīng)歷了網(wǎng)易百度騰訊研究院等幾個地方,陸續(xù)做過游戲頁游瀏覽器移動端翻譯等。四既要有攻城之力,也要有熬戰(zhàn)之氣產(chǎn)品開發(fā)完成后,必然有。功能開發(fā)完成后,就要開始守城了。 本文由云+社區(qū)發(fā)表 在一線做了十年的開發(fā),經(jīng)歷了網(wǎng)易、百度、騰訊研究院、MIG 等幾個地方,陸續(xù)做過 3D 游戲、2D 頁游、瀏覽器、移動端翻譯 app 等。 積累了一些感悟。必然有依然幼...
閱讀 1904·2021-11-09 09:46
閱讀 2486·2019-08-30 15:52
閱讀 2445·2019-08-30 15:47
閱讀 1320·2019-08-29 17:11
閱讀 1746·2019-08-29 15:24
閱讀 3501·2019-08-29 14:02
閱讀 2442·2019-08-29 13:27
閱讀 1199·2019-08-29 12:32