Fork me on GitHub

使用poi导出Excel表格,jar包冲突

HTTP Status 500 – Internal Server Error
Type Exception Report
Message Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCellStyle.setAlignment(S)V
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCellStyle.setAlignment(S)V
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.rongdu.cashloan.core.common.web.filter.PerformanceMonitorFilter.doFilterWithProfile(PerformanceMonitorFilter.java:57)
com.rongdu.cashloan.core.common.web.filter.PerformanceMonitorFilter.doFilter(PerformanceMonitorFilter.java:43)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
com.rongdu.cashloan.core.common.web.filter.RemoteAddressFilter.doFilter(RemoteAddressFilter.java:51)
org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause

我的解决思路:

首先,我查看了业务代码,在导出Excel表格的时候需要一些必要的参数,标题,打印数据,Excel表格格式等....先确保业务代码没有问题。

第二,在确保业务代码没有问题的前提下,分析异常,(Message Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCellStyle.setAlignment(S)V)提示信息为没有找到当前方法。如果找不到方法,那么编译的时候是不是应该提示出来。既然编译的时候没有报错,运行时出现,最有可能的是没有找到相应的包,找不到包的错误有一下几种

1.jar包没有导入;

2.jar存在,版本不正确;

3.jar存在,都放在lib下,由于引入的其他jar有使用同样的jar,但是版本不一样。导致jar包冲突。

第1种,在maven中添加,不是maven项目的,自行加入lib中。

第2种和第3种,打印使用类的引用路径。用以确定包的具体路径。然后反编译看看里面是否有相应的方法。如果有还会报错,那要么换高版本的,要么换低版本的包(HSSFWorkbook类名)

System.out.println("引用包路径为:"+HSSFWorkbook.class.getProtectionDomain().getCodeSource().getLocation());

第三,由于业务暂时不需要使用另外一个第三方的jar,我直接在pom中添加<scope>provided</scope>,也可以在对应的jar包中添加

<exclusions>
   <exclusion>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
   </exclusion>
</exclusions>

第四,可以使用Maven Helperjar的依赖关系进行分析,详细请参考:https://blog.csdn.net/noaman_wgs/article/details/81137893,由于讲的很详细,不在描述。

 

参考路径:

https://www.cnblogs.com/qxqbk/p/7655307.html

 

posted @ 2019-06-10 17:00  Geek仁杰  阅读(3608)  评论(0编辑  收藏  举报