• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using ClassPathXmlApplicationContext to load beans

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my interface


this is my class


this is my main class


this is my xml file


this works fine

i need to load beans using ApplicationContext Container.

i change my main class to this



my CarApp.xml is in Project folder.

it is not working

here is error

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the config file on the classpath? It needs to be; it's not.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added xml file to src folder.now it is working.


1)anyway what are the other places consider as a classpath without src folder ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you worked it out :)

The "default" classpath depends on the environment you're running in and how you're running the application.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Eclips IDE and running as a Java application
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the classpath is determined by your runtime configuration, which in turn is influenced by how your project is configured. For example, if you have multiple source directories, they'll all get compiled to the configured output directory (there are several ways to configure output directories).
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lets imagin i don't like to put my xml file to src folder.
so i need it to put Diretly to project folder.

1)if i did that way how can i use ClassPathXmlApplicationContext to load beans?
2)or is there any other best way to do this other than using src folder?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as the file is on the classpath it doesn't matter where it is. For example, a Maven application would put config files in src/main/resource. So you could create another source directory and put it there. Putting it at the root level of your project itself, in my opinion, is a bad idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic