Java – Spring Boot – Unable to resolve Whitelabel Error Page

javajspspring-bootspring-mvc

I am trying to run a simple Spring boot application from 2 days but still unable to make it work. I checked all the related questions and blogs but still issue persist.

My project structure appears as below.

Project Structure

POM.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
     <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
</dependencies>

WebApplication.java

@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer{


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebApplication.class);
    }

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

}

Application.properties

server.servlet.context-path=/EBS-web
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
logging.level.org.springframework.web=DEBUG

LoginController

@Controller
public class LoginController {

    @RequestMapping(path="/")
    public String login() {
        System.out.println("******************logging************************");
        return "login";
    }

}

Login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hi Login
</body>
</html>

Whenever I try to run the application as Spring Boot App (STS plugin for Eclipse) and access the http://localhost:8080/EBS-web/
It gives below error message on UI

Whitelabel Error Page This application has no explicit mapping for
/error, so you are seeing this as a fallback.

Sun Sep 23 17:34:52 IST 2018 There was an unexpected error (type=Not
Found, status=404). No message available

From the below stack trace, I can see spring is able to fetch the handler method but not able to find the associated view.

2018-09-23 17:44:12.248 DEBUG 14728 — [nio-8080-exec-2]
o.s.web.servlet.DispatcherServlet : Last-Modified value for
[/EBS-web/] is: -1

******************logging************************

2018-09-23 17:44:12.258 DEBUG 14728 — [nio-8080-exec-2]
o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are
[text/html, application/xhtml+xml, image/webp, image/apng,
application/xml;q=0.9, /;q=0.8] based on Accept header types and
producible media types [/]) 2018-09-23 17:44:12.258 DEBUG 14728 —
[nio-8080-exec-2] o.s.w.servlet.view.BeanNameViewResolver : No
matching bean found for view name 'login' 2018-09-23 17:44:12.260
DEBUG 14728 — [nio-8080-exec-2]
o.s.w.s.v.ContentNegotiatingViewResolver : Returning
[org.springframework.web.servlet.view.JstlView: name 'login'; URL
[/WEB-INF/jsp/login.jsp]] based on requested media type 'text/html'
2018-09-23 17:44:12.260 DEBUG 14728 — [nio-8080-exec-2]
o.s.web.servlet.DispatcherServlet : Rendering view
[org.springframework.web.servlet.view.JstlView: name 'login'; URL
[/WEB-INF/jsp/login.jsp]] in DispatcherServlet with name
'dispatcherServlet' 2018-09-23 17:44:12.264 DEBUG 14728 —
[nio-8080-exec-2] o.s.web.servlet.view.JstlView :
Forwarding to resource [/WEB-INF/jsp/login.jsp] in
InternalResourceView 'login' 2018-09-23 17:44:12.266 DEBUG 14728 —
[nio-8080-exec-2] o.s.web.servlet.DispatcherServlet :
DispatcherServlet with name 'dispatcherServlet' processing GET request
for [/EBS-web/WEB-INF/jsp/login.jsp] 2018-09-23 17:44:12.267 DEBUG
14728 — [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping :
Looking up handler method for path /WEB-INF/jsp/login.jsp 2018-09-23
17:44:12.268 DEBUG 14728 — [nio-8080-exec-2]
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method
for [/WEB-INF/jsp/login.jsp] 2018-09-23 17:44:12.268 DEBUG 14728 —
[nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching
patterns for request [/WEB-INF/jsp/login.jsp] are [/**]

Best Answer

Add @RestController instead of @Controller. Then run your Java application. this should solve the WhiteLabel error

Related Topic