aspose file tools*
The moose likes Beginning Java and the fly likes what is diff in Spring's ClassPathResource and FileSystemResource class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is diff in Spring Watch "what is diff in Spring New topic
Author

what is diff in Spring's ClassPathResource and FileSystemResource class

ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
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

Joined: Aug 16, 2005
Posts: 13875
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
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
 
subject: what is diff in Spring's ClassPathResource and FileSystemResource class
 
Similar Threads
Strange Spring problem
Spring and command line arguments
how to use spring context loader
spring context loader
spring