2017-04-12 78 views
0

我寫了一個作業,讀取基於GitHub的項目彈簧伸展Excel中的Excel文件,失敗並初始化Excel的讀者 - 春季批處理作業

代碼波紋管:

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

,但我面對這樣的錯誤:org.springframework.batch.item.ItemStreamException: Failed to initialize the reader

它給了我,它的原因包括:

java.util.zip.ZipException:無效塊類型 PS:xls文件紅色正確,問題是當我使用擴展名時:.xlsx

有什麼建議嗎?

等待你的幫助!

THX

+1

提供鏈接到GitHub的項目,最有可能的讀者不能找到用'resource'指定的文件。嘗試類似'value = classpath:Vignettes.xlsx''如果該文件存在於'classpath'中。 –

+0

沒有堆棧跟蹤很難,但可能資源屬性值錯誤;添加完整文件路徑或類路徑:\ –

+0

我想這樣..錯誤不是由類路徑引起的:/ – inarmag

回答

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>