Getting Whitelabel Error Page with status "404" While running Spring Boot Application

By Yashwant Chavan, Views 46, Last updated on 19-Apr-2019

I am trying to build & run the Spring Boot application with simple RestController. After hitting the RequestMapping URL, I am getting Whitelabel Error Page with status code "404".

tags spring spring-boot

Error

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Apr 13 10:34:51 IST 2019 There was an unexpected error (type=Not Found, status=404). No message available

Spring Boot Application - Whitelabel Error Page with status 404

Spring Boot Application Class

package com.technicalkeeda.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

Rest Controller

After hitting URL http://localhost:8080/hello getting Whitelabel Error Page.

package com.technicalkeeda.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

	@RequestMapping("/hello")
	public String index() {
		return "Spring Boot Example!!";
	}

}

Server Startup logs

No error observed on Spring boot embedded tomcat server startup.


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.2.RELEASE)

2019-04-13 10:24:21.792  INFO 10084 --- [           main] com.technicalkeeda.app.Application       : Starting Application on DESKTOP-V839OVQ with PID 10084 (C:\java-projects\SpringBoot\target\classes started by Yashwant in C:\java-projects\SpringBoot)
2019-04-13 10:24:21.798  INFO 10084 --- [           main] com.technicalkeeda.app.Application       : No active profile set, falling back to default profiles: default
2019-04-13 10:24:22.002  INFO 10084 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@667a738: startup date [Sat Apr 13 10:24:21 IST 2019]; root of context hierarchy
2019-04-13 10:24:26.572  INFO 10084 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-04-13 10:24:26.974  INFO 10084 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-04-13 10:24:26.975  INFO 10084 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2019-04-13 10:24:27.014  INFO 10084 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Java\jdk1.8.0_144\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre1.8.0_144/bin/server;C:/Java/jre1.8.0_144/bin;C:/Java/jre1.8.0_144/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Java\jdk1.8.0_144\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\Geth;C:\Program Files\nodejs\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\apache-maven-3.3.9\bin;C:\Program Files\Microsoft VS Code\bin;C:\xampp\php;C:\composer;C:\WINDOWS\System32\OpenSSH\;C:\Ruby24-x64\bin;C:\Users\Yashwant\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\bin;C:\Program Files\Java\jdk-9.0.1\bin;C:\Program Files\Geth;C:\Program Files\nodejs\node_modules\npm\bin;C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Program Files\nodejs;C:\Users\Yashwant\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\OpenSSL\bin;C:\OpenSSL\include\openssl;C:\sqlite-dll-win64-x64-3240000;C:\Users\Yashwant\AppData\Roaming\Composer\vendor\bin;C:\Program Files\php-7.2.8-src;;C:\eclipse-java-kepler\eclipse;;.]
2019-04-13 10:24:27.291  INFO 10084 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-04-13 10:24:27.292  INFO 10084 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5296 ms
2019-04-13 10:24:27.590  INFO 10084 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-04-13 10:24:27.599  INFO 10084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-04-13 10:24:27.600  INFO 10084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-04-13 10:24:27.600  INFO 10084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-04-13 10:24:27.601  INFO 10084 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-04-13 10:24:27.937  INFO 10084 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-04-13 10:24:28.536  INFO 10084 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@667a738: startup date [Sat Apr 13 10:24:21 IST 2019]; root of context hierarchy
2019-04-13 10:24:28.717  INFO 10084 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-04-13 10:24:28.720  INFO 10084 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-04-13 10:24:28.800  INFO 10084 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-04-13 10:24:28.800  INFO 10084 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-04-13 10:24:29.226  INFO 10084 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-04-13 10:24:29.442  INFO 10084 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-04-13 10:24:29.450  INFO 10084 --- [           main] com.technicalkeeda.app.Application       : Started Application in 8.568 seconds (JVM running for 11.559)
2019-04-13 10:24:41.165  INFO 10084 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2019-04-13 10:24:41.166  INFO 10084 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2019-04-13 10:24:41.210  INFO 10084 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 44 ms

Solution

Bootstrap class Application.java should know the package or the class path where it should refer in order access the controller.

Hence you need to specify @ComponentScan(basePackages= {"com.technicalkeeda"} on top of your Bootstrap class. Here I have specified base package like com.technicalkeeda.

package com.technicalkeeda.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages={"com.technicalkeeda"})
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]