• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

using ClassPathXmlApplicationContext to load beans

 
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

 
Author
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
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
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
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.
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!