大佬们,我采用easypoi进行excel上传解析,本地post以及自启前后端页面测试都OK,部署服务器后报错 具体代码如下: 入口: @PostMapping("/importReFai") public R importReFai(@RequestPart("file") MultipartFile file) { faiStartService.importReFaiExcel(file); return R.ok(); }
服务层:
@Override
public void importReFaiExcel(MultipartFile file) {
ExcelImportResult<FaiReStartExcelVO> result = ExcelUtils.importExcelMore(file, 0, 1,
FaiReStartExcelVO.class);
if (result == null){
log.error("excel文件解析失败失败");
throw new RRException("excel文件解析失败失败");
}
……
}
ExcelUtils工具类:
public static <T> ExcelImportResult<T> importExcelMore(MultipartFile file, Integer titleRows, Integer
headerRows, Class<T> pojoClass){
if (file != null && !file.isEmpty()) {
//文件名称
int begin = Objects.requireNonNull(file.getOriginalFilename()).indexOf(".");
//文件名称长度
int last = file.getOriginalFilename().length();
//判断文件格式是否正确
String fileName = file.getOriginalFilename().substring(begin, last);
if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
throw new RRException("上传文件格式有误,仅支持xls、xlsx文件");
}
} else {
throw new RRException("该文件无数据");
}
ImportParams params = new ImportParams();
//设置title行(一般为第一行 index=0)
params.setTitleRows(titleRows);
//
params.setHeadRows(headerRows);
//设置验证支持 验证支持开开之后才会判断实体类中的限制i套件
params.setNeedVerify(true);
ExcelImportResult<T> result;
try {
result = ExcelImportUtil.importExcelMore(file.getInputStream(), pojoClass, params);
} catch (Exception e) {
throw new RRException("解析excel文件失败", e);
}
return result;
}
服务报错信息:
2023-05-12 11:01:33.469 ERROR 58848 --- [http-nio-58080-exec-19] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filtered request failed.] with root cause
java.lang.NoClassDefFoundError: org/apache/tomcat/util/http/Parameters$FailReason at org.apache.catalina.connector.Request.parseParameters(Request.java:3281) at org.apache.catalina.connector.Request.getParameter(Request.java:1113) at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381) at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:158) at io.renren.modules.sys.oauth2.OAuth2Filter.getRequestToken(OAuth2Filter.java:103) at io.renren.modules.sys.oauth2.OAuth2Filter.onAccessDenied(OAuth2Filter.java:58) at org.apache.shiro.web.filter.AccessControlFilter.onAccessDenied(AccessControlFilter.java:133) at org.apache.shiro.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:162) at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203) at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) 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:387) 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:358) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
2023-05-12 11:01:33.470 ERROR 58848 --- [http-nio-58080-exec-19] i.r.common.exception.RRExceptionHandler : Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/multipart/support/StandardMultipartHttpServletRequest
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/multipart/support/StandardMultipartHttpServletRequest at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:394) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253) at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:348) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:173) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NoClassDefFoundError: org/springframework/web/multipart/support/StandardMultipartHttpServletRequest at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:87) at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1178) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1012) ... 28 common frames omitted
网上查了好多案例,还是找不到正确的原因以及解决方案。请大神们赐教。
根据您提供的错误信息,似乎是缺少了org.apache.tomcat.util.http.Parameters.FailReason
类,这个类应该是Tomcat中的一个内部类,而根据您提供的信息,您的应用可能是运行在Tomcat上的。
这个问题可能是由于版本不兼容引起的,具体的解决方法您需要根据您的应用和Tomcat的版本进行判断,常见的解决方法包括:
1.将应用中Tomcat相关的依赖修改为与服务器上的Tomcat版本一致
2.将应用中的编译目标版本修改为与服务器上的Java版本一致
3.将Tomcat版本降级到与应用中的Tomcat版本保持一致
4.在代码中将与Tomcat相关的类或方法修改,适配服务器上的Tomcat版本
根据您提供的错误信息,可以看出是缺少 org/apache/tomcat/util/http/Parameters$FailReason 类。这个类是 Tomcat 的一个类,可能是由于 Tomcat 版本不兼容或者缺少相关的依赖导致的。
您可以尝试升级 Tomcat 版本或者添加缺少的依赖,具体方法如下:
升级 Tomcat 版本:如果您使用的是较旧的 Tomcat 版本,可以尝试升级到最新版本,或者升级到与您的应用程序兼容的版本。
添加缺少的依赖:根据错误信息,缺少的类是 org/apache/tomcat/util/http/Parameters$FailReason,可以尝试添加相关依赖,例如:
org.apache.tomcat tomcat-util 9.0.53 xml 需要注意的是,上述依赖版本号需要根据您实际使用的 Tomcat 版本进行调整。
如果以上方法都无法解决问题,建议您尝试联系服务器管理员或者 Tomcat 官方支持人员进行进一步排查。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。