2016-06-21 100 views
0

在彈簧引導應用程序中顯示自定義的welcome.jsp時遇到問題。如何在spring啓動時顯示「welcome.jsp」?

,而我想顯示自定義的JSP文件 「的welcome.jsp」 它始終顯示 「的index.html」 ..

請求幫助。在application.properties

+0

要求任何工作實例句柄.. –

+0

請加web.xml和的applicationContext。 xml文件 –

+0

請顯示您的代碼和配置文件。 – Patrick

回答

1

1)確保選擇用SpringMVC

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

2)添加的src /主/ web應用/ WEB-INF/JSP /的welcome.jsp

3)修改應用程序是這樣的:

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"); 
    } 
} 

請參考http://docs.spring.io/spring/docs/4.2.6.RELEASE/spring-framework-reference/htmlsingle/#mvc-config-view-controller

然後,運行applicati上,你可以找到日誌: 根映射到類型[類org.springframework.web.servlet.mvc.ParameterizableViewController]

+0

我的應用程序實現了SpringBootServletInitializer。那麼在這種情況下如何包含'WebMvcConfigurerAdapter'?我應該把它作爲靜態的內部類嗎?請在我的Application類下面找到:public class WebApplication extends SpringBootServletInitializer {....} –

+0

非常感謝...它的工作... :) –

+0

創建另一個類擴展WebMvcConfigurerAdapter並註釋@Configuration,或實現WebMvcConfigurer接口:) – lenicliu

相關問題