File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes GenericXmlApplicationContext classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "GenericXmlApplicationContext classpath" Watch "GenericXmlApplicationContext classpath" New topic
Author

GenericXmlApplicationContext classpath

Gabriela Rios
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
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

Joined: Feb 27, 2008
Posts: 32
I changed it to:
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Gabriela Rios
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
Thanks for the clarification
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

majid nakit,
Your post was moved to a new topic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: GenericXmlApplicationContext classpath