2016-06-21 102 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

相关问题