无法初始化Excel阅读器 - 弹簧批处理作业

时间:2017-04-12 10:44:34

标签: spring spring-batch

我写了一份工作,根据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

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,这是一个与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>