wood burning stoves*
The moose likes Spring and the fly likes using ClassPathXmlApplicationContext to load beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "using ClassPathXmlApplicationContext to load beans" Watch "using ClassPathXmlApplicationContext to load beans" New topic
Author

using ClassPathXmlApplicationContext to load beans

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
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

Joined: Sep 29, 2008
Posts: 12617

Is the config file on the classpath? It needs to be; it's not.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 08, 2010
Posts: 510
I am using Eclips IDE and running as a Java application
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 08, 2010
Posts: 510
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
GeeCON Prague 2014
 
subject: using ClassPathXmlApplicationContext to load beans