How to use Spring ClassPathResource: with classpath: or classpath *: and leading / or not?

I have a file in place

--src --> main --> config --> application --> context --> reference --> user --> user.xml 

Where

  --src --> main --> config 

is on the way to classes. Now I'm trying to access the file using

 Resource resource = new ClassPathResource("classpath**:/application/context/references/user/user.xml"); File file = resource.getFile(); 

But I get a FileNotFoundException , I tried with

 Resource resource = new ClassPathResource("classpath:/application/context/references/user/user.xml"); File file = resource.getFile(); 

too, but still I get an exception. Can someone help me understand the operation of ClassPathResource and the correct solution?

+10
source share
1 answer

Use as below

 Resource resource = new ClassPathResource("/application/context/references/user/user.xml"); File file = resource.getFile(); 
+15
source

All Articles