我正在为项目使用struts2。用户可以请求从网页下载文件,此请求将在后台处理。为了使它工作,我必须创建一个需要传入servletContext对象的调度程序。
//MockServletContext comes from the spring framework
MockServletContext context = new MockServletContext("file:directory");
//Initialize a dispatcher
StrutsTestCaseHelper.initDispatcher(context, map);
我的日志文件输出了一堆错误,以及“无法读取类”异常的一个示例:
ERROR [com.opensymphony.xwork2.util.finder.DefaultClassFinder] - Unable to read class [one.action.class.path]
java.lang.ArrayIndexOutOfBoundsException: 10792
at org.objectweb.asm.ClassReader.readClass(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.opensymphony.xwork2.util.finder.DefaultClassFinder.readClassDef(DefaultClassFinder.java:473)
at com.opensymphony.xwork2.util.finder.DefaultClassFinder.<init>(DefaultClassFinder.java:96)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildClassFinder(PackageBasedActionConfigBuilder.java:416)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.findActions(PackageBasedActionConfigBuilder.java:397)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:354)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:274)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
at org.apache.struts2.util.StrutsTestCaseHelper.initDispatcher(StrutsTestCaseHelper.java:58)
还有另一种例外:
[org.springframework.mock.web.MockServletContext] - Couldn't determine real path of resource class path resource [one/resource/path/resource]
java.io.FileNotFoundException: class path resource [one/resource/path/resource] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/user/dev/project/build_output/splice_links/da39a3ee5e6b4b0d3255bfef95601890afd80709/resources/resource.jar!one/resource/path/resource
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:192)
at org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:167)
at org.springframework.mock.web.MockServletContext.getRealPath(MockServletContext.java:396)
at freemarker.cache.WebappTemplateLoader.findTemplateSource(WebappTemplateLoader.java:95)
at freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:75)
at org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader.findTemplateSource(FreemarkerThemeTemplateLoader.java:37)
at freemarker.cache.TemplateCache.findTemplateSourceAndLog(TemplateCache.java:729)
at freemarker.cache.TemplateCache.lookupTemplateWithAcquisitionStrategy(TemplateCache.java:681)
at freemarker.cache.TemplateCache.access$500(TemplateCache.java:54)
at freemarker.cache.TemplateCache$TemplateCacheTemplateLookupContext.lookupWithAcquisitionStrategy(TemplateCache.java:861)
at freemarker.cache.TemplateCache$TemplateCacheTemplateLookupContext.lookupWithLocalizedThenAcquisitionStrategy(TemplateCache.java:868)
at freemarker.cache.TemplateLookupStrategy$Default020300.lookup(TemplateLookupStrategy.java:98)
at freemarker.cache.TemplateCache.lookupTemplate(TemplateCache.java:667)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:375)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:249)
at freemarker.template.Configuration.getTemplate(Configuration.java:1537)
at freemarker.template.Configuration.getTemplate(Configuration.java:1401)
我在堆栈溢出上阅读了很多帖子,但没有一个对我有帮助。我是否需要向MockServletContext
添加一些配置。
愿任何人告诉我如何解决这个错误。如果您需要我发布更多文件/信息,请告诉我。
pom.xml
中的asm依赖:
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
答案 0 :(得分:0)
出现以下错误,
java.lang.ArrayIndexOutOfBoundsException: 10792
at org.objectweb.asm.ClassReader.readClass(Unknown Source)
我认为,您需要检查项目中是否使用了正确版本的asm jar文件。