• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

what is diff in Spring's ClassPathResource and FileSystemResource class

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
reply
    Bookmark Topic Watch Topic
  • New Topic