• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resource loading from system file path VS classpath

 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that we can load a resource say an XML context definition file using the FileSysytemXmlApplicationContext or ClassPathXmlApplicationContext.While the former loads the resource from a system file location path, the latter does it by searching the classpath(even in Jar files).
Are there any pros and cons of these modes of resource loading?Isn't file system loading more faster as compared to searching on the classpath?
Should there be any considerations when developing our applications to load resources?
I understand that since loading of resources would be mostly at application startup, it should not be a major issue.But still is there any significance from the application point of view?
 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any opinions on the same?I am still looking for some replies.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil Sun wrote:I understand that we can load a resource say an XML context definition file using the FileSysytemXmlApplicationContext or ClassPathXmlApplicationContext.While the former loads the resource from a system file location path, the latter does it by searching the classpath(even in Jar files).
Are there any pros and cons of these modes of resource loading?Isn't file system loading more faster as compared to searching on the classpath?
Should there be any considerations when developing our applications to load resources?
I understand that since loading of resources would be mostly at application startup, it should not be a major issue.But still is there any significance from the application point of view?


I guess for me it depends on whether the configuration file is in the jar/war/ear file. In that case I would use classpath, for war files I put it in the WEB-INF directory and use http: or XmlWebApplicationContext. Sometimes you are including a third party jar from someone else and the file is in the classpath, so in order to load it up, it has to be via classpath. Sometimes the file is outside the archive file and you have to use FileSystem.

In any case I always prefix all my locations with either "classpath:" "file:" or "http:" so that it doesn't matter which ApplicationContext version you use, it will always load the files based on the prefix.

Hope that helps clarify things for you

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic