Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is diff in Spring's ClassPathResource and FileSystemResource class

 
ganesh pol
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i do'nt know where to ask this question on this forum but most appropriate is java in general i think

i am new to Spring can any one on this earth can help me
what is diff in Spring's ClassPathResource and FileSystemResource class

when to use which class?

Resource res = new FileSystemResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);


ClassPathResource res = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also new to Spring (doing a course the past two weeks and next week...), but the names sound quite logical to me:

ClassPathResource looks for the resource on the classpath, FileSystemResource looks for it in the file system.

Ofcourse, if the resource is in the current directory and the current directory is in the classpath, it doesn't make a difference in your example.
 
ganesh pol
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Jesper de Jong

and sorry for coming with one new confusion
but after reading certain things i have confused

as you posted before

ClassPathResource looks for the resource on the classpath, FileSystemResource looks for it in the file system


what do u mean by classpath it is little confusing

consider following code


when i commented statement 1 and use 2nd statement it gives me Exception

C:\SPRING~2>java HelloClient vhff
please Wait.
15-Nov-2005 14:00:27 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [c:/hello.xml]
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path re
source [c:/hello.xml]; nested exception is java.io.FileNotFoundException: class path resource [c:/hello.xml] cannot
be opened because it does not exist
Exception in thread "main" java.lang.NullPointerException
at HelloClient.main(HelloClient.java:31)

when i commented statement 2 and use 1st statement it gives me output

my Question is what is the meaning of classpath regarding this

because when i copy the file ("hello.xml") in the same folder as that of the class and used statement 2 with slight modification it gives me no error

ApplicationContext cont=new ClassPathXmlApplicationContext("hello.xml");
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic