Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource

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

like image 662
walid zaidouh Avatar asked Oct 28 '25 20:10

walid zaidouh


1 Answers

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

like image 110
Arpit Tripathi Avatar answered Oct 30 '25 11:10

Arpit Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!