• 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
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

About classpath prefix in ClassPathXmlApplicationContext  RSS feed

 
Ranch Hand
Posts: 1730
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.
 
Ranch Hand
Posts: 380
2
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
Ranch Hand
Posts: 380
2
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.
 
Are we home yet? Wait, did we forget the tiny ad?
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!