4

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

4
  • 1
    try prefix path resource with file:// Commented Jan 24, 2015 at 14:39
  • 1
    I wouldn't recommend using a relative URL like that for your input location in your configuration file. What happens when you fully qualify it as well as adding the file:// as Luca mentions? Commented Jan 24, 2015 at 20:08
  • ten thousand views and no one thinks it's a good question. Well, you got my vote at least! Commented Oct 30, 2020 at 16:26
  • I ran into this issue when working with Michael Minella's excellent Spring Batch book using IntelliJ. In IntelliJ, right click on src/main/resources directory and select "Mark Directory as -> Resources Root". Strange thing is that I tried "Mark Directory as -> Unmark Resources Root", restarted IntelliJ, cleaned up all IntelliJ files to reproduce original issue and was not able to re-produce it. I'm thinking it is just an IntelliJ quirk that resources was not in the classpath. Commented Dec 9, 2020 at 3:32

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.