I am developing a small spring mvc app.
I have spring-context.xml file containing spring MVC's dispatcher servlet configuration.
root-context.xml as application context.
I am declaring my Datasource/daoimpl beans in root-context.xml file.
How do i access root-context.xml file in controller class and invoke getBeans() method on it to get the beans?
Below is lines of code from controller class.
This is one of the several ways I tried accessing it.
root-context.xml file is declared in web.xml file as context param.
Is there a way I can access this "contextConfigLocation" parameter in my controller class to access this xml file?
Complete path of all the files mentioned is :
/SpringMVCStudent/src/main/webapp/WEB-INF/spring/root-context.xml /SpringMVCStudent/src/main/java/java9s/springmvcstudent/controller/StudentController1.java /SpringMVCStudent/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml /SpringMVCStudent/src/main/webapp/WEB-INF/web.xml
Its a problem in one trivial line of code which took my entire day and still not solved.
Thanks in advance
Surendra is correct. Don't implement BeanFactoryAware or have a reference to ApplicationContext at all. Do not call getBean(), this defeats the whole purpose of dependency injection. In your case you need a particular Spring bean, let Spring provide it (using @Autowired) there is no need to look it up from the context.
Thank you all for your responses. I am sure that is the solution to this problem I was having.
As I tried to make the changes and see for myself in eclipse, my project has become unstable.
Showing errors everywhere, in all files. in pom.xml it shows the following msg as error:
"Lifecycle mapping "org.eclipse.m2e.jdt.JarLifecycleMapping" is not available. To enable full functionality, install the lifecycle mapping and run Maven->Update Project