title: Spring:-HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
body: <p>Error:-<br>
  HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException</p>
  
  <pre><code>type Exception report
  
  message Request processing failed; nested exception is java.lang.NullPointerException
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  java.lang.NullPointerException
      com.service.onlineServicesImpl.savEmployee123(onlineServicesImpl.java:33)
      com.controller.OnlineBankingController.createNewAccount(OnlineBankingController.java:38)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs.
  
  Apache Tomcat/7.0.67
  
  
  
  
  spring-distchper-servlet.xml
  
  &lt;context:component-scan base-package="com.controller" /&gt;
      &lt;context:annotation-config /&gt;
      &lt;mvc:annotation-driven/&gt;
  
      &lt;bean id="emp" class="com.model.Employee"/&gt;
          &lt;bean id="dmds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName"  value="oracle.jdbc.driver.OracleDriver"&gt;&lt;/property&gt;  
          &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"&gt;&lt;/property&gt;  
          &lt;property name="username" value="system"&gt;&lt;/property&gt;  
          &lt;property name="password" value="Oracle@123"&gt;&lt;/property&gt;
      &lt;/bean&gt;  
      &lt;bean id="mysessionFactory"  class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;  
          &lt;property name="dataSource" ref="dmds"&gt;&lt;/property&gt;  
         &lt;property name="mappingResources"&gt;  
          &lt;list&gt;  
          &lt;value&gt;hibernate.hbm.xml&lt;/value&gt;  
          &lt;/list&gt;  
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;  
              &lt;props&gt;  
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle12cDialect&lt;/prop&gt;  
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;  
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;  
              &lt;/props&gt;  
          &lt;/property&gt;  
      &lt;/bean&gt;  
      &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate"&gt;  
      &lt;property name="sessionFactory" ref="mysessionFactory"&gt;&lt;/property&gt;  
      &lt;/bean&gt;
      &lt;bean id="eDAO" class="com.dao.EmployeeDAO"&gt;  
      &lt;property name="template" ref="hibernateTemplate"&gt;&lt;/property&gt;  
      &lt;/bean&gt;  
      &lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" &gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/pages/&lt;/value&gt; 
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Model Class :-
      package com.model;</p>
  
  <pre><code>public class Employee {
  
      private String id;
      private String name;
      private String salary;
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getSalary() {
          return salary;
      }
  
      public void setSalary(String salary) {
          this.salary = salary;
      }
  
  }
  </code></pre>
  
  <p>DAO Class:-
      package com.dao;</p>
  
  <pre><code>import org.springframework.orm.hibernate5.HibernateTemplate;
  import org.springframework.stereotype.Repository;
  import com.model.Employee;
  
  @Repository
  public class EmployeeDAO {
  
      public EmployeeDAO() {
          System.out.println("In a EmpoyeeDAO******************************");
      }
  
      private HibernateTemplate template;
  
      public void setTemplate(HibernateTemplate template) {
          System.out.println("In EmployeeDAO setter");
          this.template = template;
      }
  
      public void save(Employee e) {
  
          System.out.println("EmployeeDAO Value-------&gt; " + e.getId() + "   "
                  + e.getName() + "   " + e.getSalary());
  
          template.save(e);
  
      }
  
  }
  
  Service Class:-
  package com.service;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.dao.EmployeeDAO;
  import com.model.Employee;
  
  @Service
  public class onlineServicesImpl {
  
      @Autowired
      private EmployeeDAO dao;
  
  
      public void savEmployee123(Employee emp) {
  
          System.out.println("Employee Value-------&gt; " + emp.getId() + "   "
                  + emp.getName() + "   " + emp.getSalary());
  
          dao.save(emp);
      }
  
  }
  </code></pre>
  
  <p>This my controller Class:-</p>
  
  <pre><code>@Controller
  public class OnlineBankingController {
  
      @Autowired
      private Employee emp;
  
      @RequestMapping("accountcreation")
      public ModelAndView createNewAccount() {
  
          System.out.println("we are in createNewAccount");
          emp.setId("10");
          emp.setName("pradeep");
          emp.setSalary("500000");
  
          // dao.save(emp);
          System.out.println("Done");
  
          onlineServicesImpl obj = new onlineServicesImpl();
  
          obj.savEmployee123(emp);
  
          ModelAndView obj1 = new ModelAndView("newAccountCreation");
  
          obj1.addObject("test", "Testing for spring");
  
          return obj1;
  
      }
  }
  </code></pre>
  
  <p>//please help
      Can someone suggest what the issue in it why my this code in not working.</p>