lundi 2 mars 2015

Nullpointer in webapp on @Autowired

So I'm adding a Spring 3 autowiring & JPA/Hibernate Data Access layer to my project which has the webapp and data portions separated in different war/jars. The webapp does include the data jar as a dependency in Maven though. Everything is working fine on the data side in JUnit and deployment gives me no errors but when the page is loaded and a call to the autowired DAO bean is executing I get a NullPointerException.


The kicker is, I did not design the webapp portion, but I do have control to modify it as needed to make this work. I have a feeling this has to do with the webapp still not seeing the autowired DAO I'm trying to instantiate even thought the data jar is added as a dependency.


Does something need to be added to the webapps applicationContext in order to sync these up? I'm pretty new at this so I'm sure I'm missing something pretty obvious! I've looked at similar questions asked but nothing seems to match up to my current situation.


My data applicationContext



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:context="http://ift.tt/GArMu7"
xmlns:jee="http://ift.tt/OpNaZ5"
xmlns:lang="http://ift.tt/OGfeTY"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:util="http://ift.tt/OGfeTW"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/OpNdV1 http://ift.tt/1feTlrW
http://ift.tt/GArMu7 http://ift.tt/1jdLYo7
http://ift.tt/OpNaZ5 http://ift.tt/1feTnjL
http://ift.tt/OGfeTY http://ift.tt/1feTlrY
http://ift.tt/OGfeU2 http://ift.tt/18tm2Tg
http://ift.tt/OGfeTW http://ift.tt/1feTls0">

<context:annotation-config/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<property name="persistenceUnitName" value="ApplicationEntityManager" />
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="***" />
<property name="username" value="***" />
<property name="password" value="***" />
</bean>

<context:component-scan base-package="...data.dao"/>
<context:component-scan base-package="...data.service"/>

</beans>


Their webapp "applicationContext (Dispatcher-Servlet)



<beans xmlns="http://ift.tt/GArMu6"
xmlns:mvc="http://ift.tt/1bHqwjR"
xmlns:context="http://ift.tt/GArMu7"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="
http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/1bHqwjR
http://ift.tt/1bVJL9q
http://ift.tt/GArMu7
http://ift.tt/QEDs1k">

<context:component-scan base-package="...web.controllers" />

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>

<bean name="/mypractice/*" class="...web.controllers.MyPracticeController">
</bean>

<bean name="/milestones/*" class="...web.controllers.MilestonesController">
</bean>

<bean name="/resources/*" class="...web.controllers.ResourcesController">
</bean>

<bean name="/file/*" class="...web.controllers.FilesController">
</bean>

<bean id="uploader" class="...web.service.FileUploadRestService">
</bean>

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
</bean>

<bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />

<mvc:annotation-driven />

</beans>


Their web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/nSRXKP"
xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/1eWqHMP" id="WebApp_ID" version="3.0">


<display-name>Webapp</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

Aucun commentaire:

Enregistrer un commentaire