• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GenericXmlApplicationContext classpath

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm trying to learn Spring3 by following book Pro Spring3. I'm in chapter 4 where the author explains IoC and DI. He uses GenericXmlApplicationContext to specify the configuration file. He does the following:



My question is how does it know exactly where app-context-annotation.xml is? I have this class in a package and my xml is in META-INF/spring/app-context-annotation.xml. How can I specify that the file is there? If I have it like the book says, I get:

IOException parsing XML document from class path resource [app-context-annotation.xml]; nested exception is java.io.FileNotFoundException: class path resource [app-context-annotation.xml] cannot be opened because it does not exist

My structure is

src/main/resources/
META-INF/spring/app-context-annotation.xml

src/main/java
com.package.subpackage.subsubpackage.annotation
DeclareSpringComponents.java

Thanks

Gabriela
 
Gabriela Rios
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed it to:
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, in the book there is that "classpath:" in the front of the file name. That tells Spring to look in the classpath for the file. But without any pathing after classpath: means that it will look for that file only in the root of the classpath. So you have to tell Spring from the root of the classpath, what is the path to the file.

In your case you are using Maven, so anything in the src/main/resources/ directory will be copied to the root of the classpath.

so

src/main/resources/mark.txt copied to the root of the classpath

src/main/resources/something/anotherDir/myfile.txt is copied to

/something/anotherDir/myfile.txt off the root of the classpath.

Mark
 
Gabriela Rios
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the clarification
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
majid nakit,
Your post was moved to a new topic.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic