I am new with Spring.
So far in my application, every time I need to use a bean I load the XML.
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
So, in every class where I need to load a particular bean I use the above line.
In terms of efficciency or right use, I would like to know if this is the correct use (I suspect it is not) or if the context should be passed as parameter everytime one class need it.
Thanks
I assume that you are using Spring in non-web application.
If you are creating new application context each time you need to retrieve a bean, it is indeed not the correct solution. You should create application context once per application.
So the solution would be as you suggest passing the application context instance to classes that need it, or to otherwise ensure that you use the same instance in your application.
One of many issues you might run into with your current setup is problem with bean scoping. Spring has singleton beans, but those are singletons only within one application context. So if you retrieve a bean that is singleton from two different application contexts, they will not be the same instance. Other issues will involve performance, because application context creation will be expensive operation.