Exception
SEVERE: Servlet.service() for servlet dispatcher threw exception
java.lang.NullPointerException at com.vaannila.domain.UsertableDAOImpl.addUser(UsertableDAOImpl.java:34)
at com.vaannila.service.UserServiceImpl.add(UserServiceImpl.java:23)
at com.vaannila.web.UserController.onSubmit(UserController.java:27)
at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:409)
at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:381)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.ap

kunal green wrote:is the line which is throwing exception is
jdbcTemplate.update(sql, args, types);//Exception line----------------------------------------------

it appears that datasource is not injected properly but i verified it from the dispatcher-servlet.xml i might be wrong but it appears correct to me.

That might be your problem. If you define the datasource in your dispatcher servlet.xml and it gets created by the DispatcherServlet, but you other classes is in the ApplicationContext created by ContextLoaderListener, then you will not be able to inject the dataSource into those classes.

Basically in a Spring MVC app you create two ApplicationContexts. One for the middle tier, your services/repositories/dataSource/transactionManager. The other ApplicationContext from the dispatcherServlet should only contain Web Layer beans like Controllers, View Resolvers and MappingHandlers

So with the two app contexts. the web layer can see the beans in the middle tier, but not the other way around.