发布于 2年前

java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no colon was found

今天在开发的过程中发现了如下错误:

java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no colon was found
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1332) ~[okhttp-3.14.9.jar:?]
at okhttp3.HttpUrl.get(HttpUrl.java:917) ~[okhttp-3.14.9.jar:?]
at okhttp3.Request$Builder.url(Request.java:165) ~[okhttp-3.14.9.jar:?]
at io.majing.client.OkHttpRequestClient.post(OkHttpRequestClient.java:17) ~[classes/:?]
at io.majing.note.listener.PostReviewListener.handle(PostReviewListener.java:70) ~[classes/:?]
at io.majing.note.listener.PostReviewListener$$FastClassBySpringCGLIB$$996d7aa4.invoke(<generated>) ~[classes/:?]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.10.jar:5.3.10]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) ~[spring-aop-5.3.10.jar:5.3.10]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.10.jar:5.3.10]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.10.jar:5.3.10]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.3.10.jar:5.3.10]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]

经过排查,再结合关键字,

Expected URL scheme 'http' or 'https' but no colon was found

估计应该是http请求出错,找到

PostReviewListener.java:70第70行

requestClient.post(DomainUrlConstant.DOMAIN_MESSAGE_URL+"/messages/send.json", gson.toJson(messageRequest));

以前的请求是直接写死的http://localhost:8080,后来修改成可以配置的变量

DomainUrlConstant.DOMAIN_MESSAGE_URL

找到此变量后,发现是DomainUrlConstant这个类没有实例化,所以常量的值为空字符串

因此在这个类上增加注解@Component,问题解决

总结:Expected URL scheme 'http' or 'https' but no colon was found这个异常一般都是url出现了空字符串。按照此思路排查问题不难解决。

©2020 edoou.com   京ICP备16001874号-3