title: Spring Boot : Whitelabel Error Page with 404 status code
body: <p>I have developed small spring boot application with jar packaging. The application use case is, user will login into application and it will display welcome page. Below is my code.</p>
  <p>Main class</p>
  <pre><code>package com.ibm.heathcare;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.ComponentScan;
  
  @SpringBootApplication
  @ComponentScan(basePackages= {&quot;com.ibm.heathcare.*&quot;})
  public class HeathcareappApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(HeathcareappApplication.class, args);
      }
  
  }
  </code></pre>
  <p>Login controller class</p>
  <pre><code>package com.ibm.heathcare.controller;
  
  import java.util.Optional;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.SessionAttributes;
  
  import com.ibm.heathcare.modal.Login;
  import com.ibm.heathcare.modal.User;
  import com.ibm.heathcare.service.AuthService;
  
  @Controller
  @SessionAttributes({&quot;userName&quot;,&quot;uid&quot;})
  public class LoginController {
      
      @Autowired
      AuthService authService;
      
      @RequestMapping(&quot;/login&quot;)
      public String showLoginPage(ModelMap model){
          //model.addAttribute(&quot;login&quot;, new Login());
          return &quot;login&quot;;
      }
      
      
        @RequestMapping(&quot;/logout&quot;) 
        public String showLogoutPage(ModelMap model){
        model.put(&quot;message&quot;, &quot;Successfully Log out...&quot;);
        return &quot;redirect:/login&quot;; 
        
        }
        @RequestMapping(&quot;/welcome&quot;)
        public String showWelcomePage(ModelMap model) {
            return &quot;welcome&quot;;
        }
       
      
      
      @RequestMapping(value=&quot;/login&quot; ,method=RequestMethod.POST)
      public String showwelcomePage(@RequestParam String uid, @RequestParam String pwd,ModelMap model){
          Optional&lt;User&gt; optUser=authService.getAuthenticate(uid, pwd);
          if(optUser.isPresent()) {
              User user=optUser.get();
              model.put(&quot;userName&quot;, user.getUserName() );
              model.put(&quot;uid&quot;, user.getUserId());
              return &quot;welcome&quot;;
          }else {
              model.addAttribute(&quot;login&quot;, new Login(&quot;&quot;,&quot;&quot;));
              model.addAttribute(&quot;errorMessage&quot;,new String(&quot;Invalid Credential&quot;));
              
              return &quot;login&quot;;
          }
          
      }
  
  }
  </code></pre>
  <p>login.jsp</p>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method=&quot;post&quot;&gt;
              User ID :&lt;input type=&quot;text&quot; name=&quot;uid&quot;/&gt;&lt;p&gt;
              Password:&lt;input type=&quot;password&quot; name=&quot;pwd&quot;/&gt;&lt;br&gt;
              &lt;input type=&quot;submit&quot; value=&quot;Login&quot; /&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>welcome.jsp</p>
  <pre><code>&lt;%@ include file=&quot;common/header.jspf&quot; %&gt;
  &lt;%@ include file=&quot;common/navigation.jspf&quot; %&gt;
  &lt;div class=&quot;jumbotron text-center&quot; &gt;
      &lt;h1&gt;Welcome&lt;h1&gt;&lt;p&gt;
      &lt;h2&gt; ${userName} &lt;/h2&gt;
  &lt;/div&gt;
  &lt;%@ include file=&quot;common/footer.jspf&quot; %&gt;
  </code></pre>
  <p>application.properties</p>
  <pre><code>#Server Configuration
  server.port = 8282
  
  #ViwResolver
  spring.mvc.view.prefix=/WEB-INF/jsp/
  spring.mvc.view.suffix=.jsp
  </code></pre>
  <p>POM.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.3.1.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.ibm&lt;/groupId&gt;
      &lt;artifactId&gt;heathcare&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;heathcareapp&lt;/name&gt;
      &lt;description&gt;Health Care Management Application&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;42.2.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
              &lt;version&gt;3.3.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;jquery&lt;/artifactId&gt;
              &lt;version&gt;1.9.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;bootstrap-datepicker&lt;/artifactId&gt;
              &lt;version&gt;1.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>Now when I have executed this application through eclipse it was working fine.
  I have built a jar of application using maven tool which created in target folder. I have executed the application jar from target folder using command line. It worked fine. But when I copy same jar to another folder on my machine and try to execute using java -jar app.jar command and hit the url http://localhost:8282/login in browser it gives me <strong>Whitelabel Error Page with status code 404.</strong>  I am not sure what is wrong with the application. I have searched lot on web and some experts suggested to explicitly write @ComponentScan with basepackage information in main class. I did same but it was not worked for me.
  In console I am getting below log.</p>
  <pre><code>2020-07-10 10:38:52.605  INFO 11788 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2020-07-10 10:38:53.888  INFO 11788 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
  2020-07-10 10:38:53.918  INFO 11788 --- [           main] c.ibm.heathcare.HeathcareappApplication  : Started HeathcareappApplication in 24.424 seconds (JVM running for 25.755)
  2020-07-10 10:39:18.728  INFO 11788 --- [nio-8282-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
  2020-07-10 10:39:18.729  INFO 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
  2020-07-10 10:39:18.730 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
  2020-07-10 10:39:18.783 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
  2020-07-10 10:39:18.784  INFO 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 54 ms
  2020-07-10 10:39:18.901 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : GET &quot;/login&quot;, parameters={}
  2020-07-10 10:39:18.916 DEBUG 11788 --- [nio-8282-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.ibm.heathcare.controller.LoginController#showLoginPage(ModelMap)
  2020-07-10 10:39:19.022 DEBUG 11788 --- [nio-8282-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8]
  2020-07-10 10:39:19.022 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.view.JstlView            : View name 'login', model {}
  2020-07-10 10:39:19.043 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.view.JstlView            : Forwarding to [/WEB-INF/jsp/login.jsp]
  2020-07-10 10:39:19.160 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
  2020-07-10 10:39:19.163 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : &quot;ERROR&quot; dispatch for GET &quot;/error&quot;, parameters={}
  2020-07-10 10:39:19.168 DEBUG 11788 --- [nio-8282-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
  2020-07-10 10:39:19.664 DEBUG 11788 --- [nio-8282-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
  2020-07-10 10:39:19.684 DEBUG 11788 --- [nio-8282-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from &quot;ERROR&quot; dispatch, status 404
  </code></pre>
  <p>Please help me to find the problem.</p>