• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GenericXmlApplicationContext classpath

 
Gabriela Rios
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I changed it to:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the clarification
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
majid nakit,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic