java.lang.IllegalStateException:输入资源必须存在(阅读器处于“严格”模式):类路径资源

wal*_*ouh 4 java spring batch-processing spring-batch

这是我的项目的形式

src
   main
        ressources
                   applicationContext.xml
target
upload
       pharmacies.txt
Run Code Online (Sandbox Code Playgroud)

这是 Spring Batch Reader

src
   main
        ressources
                   applicationContext.xml
target
upload
       pharmacies.txt
Run Code Online (Sandbox Code Playgroud)

这是我运行的批次

		<property name="resource" value="./upload/pharmacies.txt" />
		<property name="lineMapper">
			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
				<property name="lineTokenizer">
				<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
					<property name="delimiter" value=","/>
					<property name="names" value="nom,telephone,adresse,Latitude,Longitude" />
				</bean>
				</property>
				<property name="fieldSetMapper">
					<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
						<property name="targetType" value="model.Pharmacie" />
					</bean>
				</property>
			</bean>
		</property>
	</bean>
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

java.lang.IllegalStateException:输入资源必须存在(阅读器处于“严格”模式):类路径资源

Arp*_*thi 5

您现在可能已经找到解决方案了。这个错误困扰了我一段时间。那是我浏览 ClassPathResource 上的 spring Batch 文档的时候。它说,ClassPathResource 代表应该从类路径获取的资源。如果您的资源文件位于 classPath 之外,请使用 FileSystemResource 或 UrlResource。

参考: https ://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/resources.html