【问题标题】:Failed to initialize the excel reader - spring batch job无法初始化 excel 阅读器 - 春季批处理作业
【发布时间】:2017-09-08 02:31:53
【问题描述】:

我基于github项目spring-extension-excel写了一个读取excel文件的作业,

代码如下:

<bean id="VignetteItemReader" class="excel.poi.PoiItemReader">
<property name="resource" value="Vignettes.xlsx" />
<property name="rowMapper">
    <bean class="excel.mapping.PassThroughRowMapper" />
</property>
</bean>

但我遇到了这个错误:

org.springframework.batch.item.ItemStreamException: 初始化阅读器失败

它告诉我它是由以下原因引起的:

java.util.zip.ZipException:无效的块类型

PS:xls 文件是正确的红色,问题是当我使用扩展名时:.xlsx

有什么建议吗?

【问题讨论】:

  • 提供该 github 项目的链接,很可能读者无法找到resource 指定的文件。如果该文件在您的classpath 中,请尝试类似value=classpath:Vignettes.xlsx"
  • 没有堆栈跟踪很难,但可能资源属性值是错误的;添加完整文件路径或类路径:\
  • 我不这么认为..错误不是由类路径引起的:/

标签: spring spring-batch


【解决方案1】:

我找到了解决方案,它是一个与 pom.xml 相关的配置: 我应该添加以下标签:

    <resources>
              <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                    <excludes>
                         <exclude>**/*.xml</exclude>
                          <exclude>**/*.xlsx</exclude>
                          <exclude>**/*.xls</exclude>
                          <exclude>**/*.csv</exclude>
                    </excludes>
              </resource>
              <resource>
                  <directory>src/main/resources</directory>
                  <filtering>true</filtering>
                  <includes>
                    <include>**/*.version</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
              </includes>
              </resource>

              <resource>
                    <directory>src/main/resources</directory>
                    <filtering>false</filtering>
                    <includes>
                         <include>**/*.xml</include>
                          <include>**/*.xlsx</include>
                          <include>**/*.xls</include>
                          <include>**/*.csv</include>
                    </includes>
              </resource>
        </resources>
        <testResources>
              <testResource>
                    <directory>src/test/resources</directory>
                    <filtering>true</filtering>
              </testResource>
        </testResources>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 2014-06-30
    • 2012-10-19
    相关资源
    最近更新 更多