dimanche 1 mars 2015

Spring ApplicationContext with multiple context xml files from different projects in an application

I have two different projects in my application: data, web

I want to Auto wire a dao defined in my data in the web application layer.

So I created a master applicationContext.xml file in web and imported the entire Spring bean files like below



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/QEDs1e">

<import resource="data/src/main/resources/spring/applicationContext-data.xml"/>
<import resource="applicationContext.xml"/>

</beans>



@Configuration("file:**/Master-Module.xml")
public class MyService{
@Autowired
public IMyDAO myDao;
Practice practice1 = myDao.findById("3900");


The interface IMyDAO is defined in applicationContext-data.xml


When I deploy the application to Websphere and run it I get a NULL pointer exception.


Id is present in database.

It builds successfully in Maven when run as independent projects.


Below is the error I get:



2/28/15 12:45:13:902 EST] 0000009d ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [webapp-7_0-SNAPSHOT_war] [/web] [/WEB-INF/views/common/footer.jsp]: Initialization successful.
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R java.lang.NullPointerException
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at cic.web.service.MyPracticeService.retrievPracticeDetails(MyPracticeService.java:51)
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at cic.web.controllers.MyPracticeController.practicesList(MyPracticeController.java:42)
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[2/28/15 12:45:13:762 EST] 0000009d SystemErr R at java.lang.reflect.Method.invoke(Method.java:611)​

Aucun commentaire:

Enregistrer un commentaire