• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

About classpath prefix in ClassPathXmlApplicationContext

 
Ranch Hand
Posts: 1749
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I came across two examples from Spring in Action and Getting Started with Spring Framework.
One example uses new ClassPathXmlApplicationContext ("META-INFO/spring/knight.xml") and the other one uses new ClassPathXmlApplication("classpath:META-INFO/spring/applicationContext.xml")
Both knight.xml and applicationContext.xml are in resources/META-INFO/spring.
Both example works
I assume classpath prefix is always needed as the xml config file is under resources/META-INFO folder.
But why the classpath is needed in one example, but not the other?
The examples are here:
https://github.com/habuma/spring-in-action-4-samples/blob/master/Chapter_01/knight/src/main/java/sia/knights/KnightMain.java
https://github.com/getting-started-with-spring/4thEdition/blob/master/chapter%206/ch06-bean-profiles/src/main/java/sample/spring/chapter06/bankapp/BankAppWithProfile.java

Thanks in advance.
 
Rancher
Posts: 480
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The springs are pretty good at explaining things so I found the appropriate section that will explain what is going on.  https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#resources-app-ctx
 
Al Hobbs
Rancher
Posts: 480
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically because it is using a classpathxml it is already looking relative to the classpath so it doesn't matter in both cases.  If it was using filesystemxml then the classpath: in front would treat the path as relative to the classpath instead of a filesystem path.  Correct me if I'm reading it wrong.
 
Goodbye moon men. Hello tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!