• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

About classpath prefix in ClassPathXmlApplicationContext  RSS feed

 
Ranch Hand
Posts: 1732
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: 427
6
Fedora IntelliJ IDE Spring
  • 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: 427
6
Fedora IntelliJ IDE Spring
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!