本文主要是介绍项目启动报java.lang.IllegalAccessError: tried to access method,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近在对接京东代扣相关的业务,拿到京东的Demo,可以很快地把整套的流程跑下来,但当把Demo集成到项目中时,只要启动项目就不停地报错,错误信息如下:
2017-10-13 19:34:18 ERROR _500_jsp _jspService - Handler processing failed; nested exception is java.lang.IllegalAccessError: tried to access method org.apache.commons.codec.digest.DigestUtils.getDigest(Ljava/lang/String;)Ljava/security/MessageDigest; from class com.wangyin.npp.util.SignUtils
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.IllegalAccessError: tried to access method org.apache.commons.codec.digest.DigestUtils.getDigest(Ljava/lang/String;)Ljava/security/MessageDigest; from class com.wangyin.npp.util.SignUtilsat org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1305)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:979)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalAccessError: tried to access method org.apache.commons.codec.digest.DigestUtils.getDigest(Ljava/lang/String;)Ljava/security/MessageDigest; from class com.wangyin.npp.util.SignUtilsat com.wangyin.npp.util.SignUtils.digestHex(SignUtils.java:142)at com.wangyin.npp.util.SignUtils.sign(SignUtils.java:45)at com.thinkgem.jeesite.easyloan.api.jdpay.util.EnctyptUtil.sign(EnctyptUtil.java:96)at com.thinkgem.jeesite.easyloan.api.jdpay.agencypay.util.RequestUtil.enctyptData(RequestUtil.java:60)at com.thinkgem.jeesite.easyloan.api.jdpay.agencypay.util.RequestUtil.tradeRequestSSL(RequestUtil.java:40)at com.thinkgem.jeesite.easyloan.api.jdpay.agencypay.AgreementSign.agreementSignRequest(AgreementSign.java:146)at com.thinkgem.jeesite.easyloan.api.jdpay.service.AgencyPayService.agreementSignRequest(AgencyPayService.java:64)at com.thinkgem.jeesite.easyloan.api.jdpay.service.AgencyPayService$$FastClassBySpringCGLIB$$c2335cfa.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)at com.thinkgem.jeesite.easyloan.api.jdpay.service.AgencyPayService$$EnhancerBySpringCGLIB$$10c648d3.agreementSignRequest(<generated>)at com.thinkgem.jeesite.easyloan.api.jdpay.service.AgencyPayService$$FastClassBySpringCGLIB$$c2335cfa.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)at com.thinkgem.jeesite.easyloan.api.jdpay.service.AgencyPayService$$EnhancerBySpringCGLIB$$9a4e90ad.agreementSignRequest(<generated>)at com.thinkgem.jeesite.easyloan.api.jdpay.controller.AgencyPayController.agreementSignRequest(AgencyPayController.java:100)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:221)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)... 40 more
其实通过错误提示就能直接看到问题的所在,是因为jar包冲突了.我们使用的是maven管理项目的,但通过maven分析jar却找不到冲突的包所在,只能一个包一个包的找那个codec的DigestUtils,终于在项目中找到了好几个,除了容联云SDK中的codec是1.5的,其他的都跟项目的版本一致.所以,就用maven依赖的exclusion方法,将jar中的类给排除掉
然后maven的依赖树,发现类的确被排除掉了,可再重启的时候,发现还是报错.这一下子就给搞懵掉了,于是就开始了一段漫长地排查过程,经过各种排查以及找京东的技术,都没法找到问题的所在.没办法,最后只好把功能单独地启一个项目,然后把我们框架的依赖全都加上,一个一个地去试,最后发现,竟然问题还是出在容联云的那个jar包上面.这就比较奇怪了,明明已经exclusion过了,为什么还是会报错呢?然后,又对容联云的jar进行了一层一层地排除,最后发现就算把所有的都exclusion掉还是会报错,可检查maven依赖,的确都已经没有了啊.这真的就奇怪了,难道是exclusion不对.后来,仔细地分析 jar才发现,原来容联云为了方便客户集成,并不是像我们一样使用的是maven依赖那些其他需要引入的jar的,而是直接放jar源码的,这也就导致了怎么exclusion,其实jar里面的方法其实都还是能访问到的,所以也就引起了版本的冲突
这篇关于项目启动报java.lang.IllegalAccessError: tried to access method的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!