java.lang.IllegalStateException:输入资源必须存在(读者处于' strict'模式):类路径资源

时间:2015-01-24 14:08:46

标签: java spring batch-processing spring-batch

这是我项目的形式

src
   main
        ressources
                   applicationContext.xml
target
upload
       pharmacies.txt

这是Spring Batch Reader



		<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>
&#13;
&#13;
&#13;

这是我运行的批次

&#13;
&#13;
public class BatchPharmacie {

	public static void main (String [] args) throws Exception {
		ClassPathXmlApplicationContext cpt = new ClassPathXmlApplicationContext("applicationContext.xml");
		//cpt.start();
		JobLauncher jobLauncher = (JobLauncher) cpt.getBean("jobLauncher");
		Job job = (Job) cpt.getBean("importPharmacies");
		//JobParameters parameter = new JobParametersBuilder().addDate("date", new Date())
		//			.addString("input.file", "C:/envdev/travail/in/personnes.txt").toJobParameters();
		jobLauncher.run(job, new JobParameters());
	}

}
&#13;
&#13;
&#13;

我收到此错误

java.lang.IllegalStateException:输入资源必须存在(读者处于&#39;严格&#39;模式):类路径资源

1 个答案:

答案 0 :(得分:2)

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

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