1. 程式人生 > >阿裏雲短信服務報錯org.json.JSONArray.iterator()Ljava/util/Iterator

阿裏雲短信服務報錯org.json.JSONArray.iterator()Ljava/util/Iterator

ray common code error: send group erb regions 最新版本

maven依賴如下:

        <!-- 阿裏雲短信sdk -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>3.7.1</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
            <version>1.1.0</version>
        </dependency>

單元測試發短信成功,工程起來之後,調用接口報如下錯誤:

java.lang.NoClassDefFoundError: com/aliyuncs/profile/DefaultProfile
    at com.esic.commonservice.sms.aliyun.AliyunSmsSendImpl.send(AliyunSmsSendImpl.java:43)
    at com.esic.commonservice.controller.SmsController.sendShortMessage(SmsController.java:333)
    at com.esic.commonservice.controller.SmsController$$FastClassBySpringCGLIB$$4bab3b60.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:160)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:86)
    at com.esic.utils.web.ControlAspect.doAround(ControlAspect.java:207)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:626)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:680)
    at com.esic.commonservice.controller.SmsController$$EnhancerBySpringCGLIB$$8553ee48.sendShortMessage(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:208)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:135)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:859)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:769)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:86)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:970)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:904)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:971)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:874)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:848)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

找不到DefaultProfile類,包已經在maven中引入了。

再次打包執行,報錯如下:

java.lang.NoSuchMethodError: org.json.JSONArray.iterator()Ljava/util/Iterator;
    at com.aliyuncs.regions.LocalEndpointResolver.<init>(LocalEndpointResolver.java:39)
    at com.aliyuncs.profile.DefaultProfile.<init>(DefaultProfile.java:72)
    at com.aliyuncs.profile.DefaultProfile.getProfile(DefaultProfile.java:209)
    at com.esic.commonservice.sms.aliyun.AliyunSmsSendImpl.send(AliyunSmsSendImpl.java:43)
    at com.esic.commonservice.controller.SmsController.sendShortMessage(SmsController.java:333)
    at com.esic.commonservice.controller.SmsController$$FastClassBySpringCGLIB$$4bab3b60.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:160)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:86)
    at com.esic.utils.web.ControlAspect.doAround(ControlAspect.java:207)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:626)

經過排查,好像是maven鏡像倉庫中阿裏的jar包存在問題。

在http://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core 中查看最新版本,改為依賴最新版本的jar。

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.0.2</version>
        </dependency>

再次運行測試,問題解決。

{"code":"OK","requestId":"5A6A8162-99D0-4311-8041-2FD17FC9F363","bizId":"146707233133591126^0","message":"OK"}

阿裏雲短信服務報錯org.json.JSONArray.iterator()Ljava/util/Iterator