title: Servlet.service() for servlet [dispatcherServlet] in context with path - Springboot Configuration issue probably
body: <p>I am new to Springboot and I am trying to follow up a tutorials in which, I am taking a user input and storing it into db and returning msg on UI that the information is stored SUCCESSFULLY. But however I am not able to store getting below error - </p>
  
  <pre><code>2019-03-16 17:11:38.829 ERROR 4276 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/locationweb] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  
  java.lang.NullPointerException: null
      at com.testname.location.controllers.LocationController.saveLocation(LocationController.java:24) ~[classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_171]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_171]
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.16.jar:9.0.16]
      at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
  </code></pre>
  
  <blockquote>
    <p>LocationController</p>
  </blockquote>
  
  <pre><code>package com.testname.location.controllers;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import com.testname.location.entities.Location;
  import com.testname.location.service.LocationService;
  @Controller
  public class LocationController {
      @Autowired
      LocationService service;
  
      @RequestMapping("/showCreate")
      public String showCreate() {
          return "createLocation";
      }
  
      @RequestMapping("/saveLoc")
      public String saveLocation(@ModelAttribute("location") Location location, ModelMap modelMap) {
  
          Location locationSaved = service.saveLocation(location);
          String msg = "Location Saved with id: " + locationSaved.getId();
          modelMap.addAttribute("msg", msg);
          return "createLocation";
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Location</p>
  </blockquote>
  
  <pre><code>package com.testname.location.entities;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  @Entity
  public class Location {
      @Id
      private int id;
      private String code, name, type ;
      @Override
      public String toString() {
          return "Location [id=" + id + ", code=" + code + ", name=" + name + ", type=" + type + "]";
      }
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String getCode() {
          return code;
      }
      public void setCode(String code) {
          this.code = code;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public String getType() {
          return type;
      }
      public void setType(String type) {
          this.type = type;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>LocationRepository</p>
  </blockquote>
  
  <pre><code>package com.testname.location.repos;
  
  import java.util.List;
  import java.util.Optional;
  
  import org.springframework.data.domain.Example;
  import org.springframework.data.domain.Page;
  import org.springframework.data.domain.Pageable;
  import org.springframework.data.domain.Sort;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  import com.testname.location.entities.Location;
  
  @Repository("Location")
  public class LocationRepository implements JpaRepository&lt;Location, Integer&gt; {
  
      @Override
      public Page&lt;Location&gt; findAll(Pageable pageable) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; S save(S entity) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public Optional&lt;Location&gt; findById(Integer id) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public boolean existsById(Integer id) {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public long count() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public void deleteById(Integer id) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void delete(Location entity) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void deleteAll(Iterable&lt;? extends Location&gt; entities) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void deleteAll() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public &lt;S extends Location&gt; Optional&lt;S&gt; findOne(Example&lt;S&gt; example) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; Page&lt;S&gt; findAll(Example&lt;S&gt; example, Pageable pageable) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; long count(Example&lt;S&gt; example) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public &lt;S extends Location&gt; boolean exists(Example&lt;S&gt; example) {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public List&lt;Location&gt; findAll() {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public List&lt;Location&gt; findAll(Sort sort) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public List&lt;Location&gt; findAllById(Iterable&lt;Integer&gt; ids) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; List&lt;S&gt; saveAll(Iterable&lt;S&gt; entities) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void flush() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public &lt;S extends Location&gt; S saveAndFlush(S entity) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void deleteInBatch(Iterable&lt;Location&gt; entities) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void deleteAllInBatch() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public Location getOne(Integer id) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; List&lt;S&gt; findAll(Example&lt;S&gt; example) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public &lt;S extends Location&gt; List&lt;S&gt; findAll(Example&lt;S&gt; example, Sort sort) {
          // TODO Auto-generated method stub
          return null;
      }
  
  
  }
  </code></pre>
  
  <blockquote>
    <p>LocationService</p>
  </blockquote>
  
  <pre><code>package com.testname.location.service;
  
  import java.util.List;
  import java.util.Optional;
  
  import com.testname.location.entities.Location;
  
  public interface LocationService {
      Location saveLocation(Location loc);
  
      Location updateLocation(Location loc);
  
      void deleteLocation(Location loc);
  
      Location getLocationById(int id);
  
      List&lt;Location&gt; getAllLocation();
  }
  </code></pre>
  
  <blockquote>
    <p>LocationServiceImpl</p>
  </blockquote>
  
  <pre><code>package com.testname.location.service;
  
  import java.util.List;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import com.testname.location.entities.Location;
  import com.testname.location.repos.LocationRepository;
  
  @Service
  public class LocationServiceImpl implements LocationService {
      @Autowired
      private LocationRepository repo;
  
      public LocationRepository getRepo() {
          return repo;
      }
  
      public void setRepo(LocationRepository repo) {
          this.repo = repo;
      }
  
      @Override
      public Location saveLocation(Location loc) {
          return repo.save(loc);
      }
  
      @Override
      public Location updateLocation(Location loc) {
          return repo.save(loc);
      }
  
      @Override
      public void deleteLocation(Location loc) {
          repo.delete(loc);
      }
  
      @Override
      public Location getLocationById(int id) {
          return repo.findById(id).orElse(null);
  
      }
  
      @Override
      public List&lt;Location&gt; getAllLocation() {
          return repo.findAll();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>LocationWebApplication</p>
  </blockquote>
  
  <pre><code>package com.testname.location;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class LocationwebApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(LocationwebApplication.class, args);
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>application.properties</p>
  </blockquote>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/projectdb
  spring.datasource.username=***
  spring.datasource.password=***
  spring.jpa.show-sql=true
  spring.mvc.view.prefix=/WEB-INF/jsps/
  spring.mvc.view.suffix=.jsp
  server.servlet.context-path=/locationweb
  </code></pre>
  
  <blockquote>
    <p>createLocation.jsp</p>
  </blockquote>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Create Location&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form action="saveLoc" method="post"&gt;
  &lt;pre&gt;
  Id: &lt;input type="text" name="id"/&gt;
  Code: &lt;input type="text" name="code"/&gt;
  Name: &lt;input type="text" name="name"/&gt;
  Type: Urban &lt;input type="radio" name="type" value="URBAN" /&gt;
      Rural  &lt;input type="radio" name="type" value="RURAL"/&gt;
  &lt;input type="submit" value="save"/&gt;
  &lt;/pre&gt;
  &lt;/form&gt;
  ${msg}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>