Pawan Singh
Pawan Singh

Reputation: 63

How to display "welcome.jsp" in spring boot?

Facing issues while displaying customized welcome.jsp in spring boot application.

It always displays "index.html" while I want to display customized jsp file "welcome.jsp"..

Request help.

Upvotes: 1

Views: 4362

Answers (1)

lenicliu
lenicliu

Reputation: 957

1) make sure springmvc options in application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

2) add src/main/webapp/WEB-INF/jsp/welcome.jsp

3) modify Application like this:

package com.lenicliu.spring.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
public class Application extends WebMvcConfigurerAdapter {

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

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("welcome");
    }
}

Please refer to http://docs.spring.io/spring/docs/4.2.6.RELEASE/spring-framework-reference/htmlsingle/#mvc-config-view-controller

Then, run application, and you can find the log: Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]

Upvotes: 2

Related Questions