首页

通过springmvc配置freemarker访问报“java.lang.IllegalAccessError: tried to access method freemarker.ext.servlet.AllHttpScopesHashModel”异常

标签:spring-mvc,freemarker,IllegalAccessError,2.3.8,NestedServletException,异常     发布时间:2017-11-06   

一、异常描述

通过springframeworksrping-mvc框架,并配置freemarker视图渲染后(相关配置脚本实例),访问后报出“org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.IllegalAccessError: tried to access method freemarker.ext.servlet.AllHttpScopesHashModel.<init>(Lfreemarker/template/ObjectWrapper;Ljavax/servlet/ServletContext;Ljavax/servlet/http/HttpServletRequest;)V from class org.springframework.web.servlet.view.freemarker.FreeMarkerView”异常,如下所示

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.IllegalAccessError: tried to access method freemarker.ext.servlet.AllHttpScopesHashModel.<init>(Lfreemarker/template/ObjectWrapper;Ljavax/servlet/ServletContext;Ljavax/servlet/http/HttpServletRequest;)V from class org.springframework.web.servlet.view.freemarker.FreeMarkerView@b@	org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287)@b@	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)@b@	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)@b@	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)@b@	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)@b@	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)@b@	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)@b@	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)@b@	..@b@java.lang.IllegalAccessError: tried to access method freemarker.ext.servlet.AllHttpScopesHashModel.<init>(Lfreemarker/template/ObjectWrapper;Ljavax/servlet/ServletContext;Ljavax/servlet/http/HttpServletRequest;)V from class org.springframework.web.servlet.view.freemarker.FreeMarkerView@b@	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.buildTemplateModel(FreeMarkerView.java:295)@b@	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:276)@b@	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:233)@b@	at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)@b@	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)@b@	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)@b@	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)@b@	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)@b@	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)@b@	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)@b@	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)@b@	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)@b@	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)@b@	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)@b@	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)@b@	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)@b@	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)@b@	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)@b@	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)@b@	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)@b@	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)@b@	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)@b@	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)@b@	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)@b@	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)@b@	at java.lang.Thread.run(Thread.java:662)

二、解决办法

1.蒋freemarker的版本由2.3.8调整为2.3.21即可解决问题(相关的jar及pom文件下载freemarker-2.3.21.jar.rar)

<dependency>@b@   <groupId>freemarker</groupId>@b@   <artifactId>freemarker</artifactId>@b@   <version>2.3.8</version>@b@</dependency>

改为

<dependency>@b@   <groupId>freemarker</groupId>@b@   <artifactId>freemarker</artifactId>@b@   <version>2.3.21</version>@b@</dependency>
<<热门下载>>