Reputation: 111
This is the form of my project
src
main
ressources
applicationContext.xml
target
upload
pharmacies.txt
And this is the 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>
this is the batch that I run
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());
}
}
And I get this error
java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource
Upvotes: 4
Views: 16118
Reputation: 121
You might have got the solution by now. This error troubled me for some time. That is when I browsed spring batch documentation on ClassPathResource. It says, ClassPathResource represents a resource which should be obtained from the classpath. Use FileSystemResource or UrlResource if your resource file resides outside your classPath.
Reference: https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/resources.html
Upvotes: 5