IDEA spring boot+jsp 404

来源:互联网 发布:最新淘宝店铺教程视频 编辑:程序博客网 时间:2024/05/22 09:39

今天开始学习spring boot ,使用的IDE是IDEA,运行demo后,访问结果总是404,大概是下面这个样子的↓
There was an unexpected error (type=Not Found, status=404).
No message available

百度了不少解决方案,感觉说的不太细:
下面是总结出来的
首先
如果你引入的spring boot依赖版本是1.3.x

<parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-parent</artifactId>    <version>1.3.0.RELEASE</version>    <relativePath/>  </parent>

那么你可以在application.properties添加下面这两个配置
spring.view.prefix:/WEB-INF/jsp/
spring.view.suffix:.jsp
并且启动类继承SpringBootServletInitializer,覆盖configure方法
注:1.3版本的SpringBootServletInitializer 路径是org.springframework.boot.context.web.SpringBootServletInitializer

public class SpringBootSampleApplication extends SpringBootServletInitializer {    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(SpringBootSampleApplication.class);    }    public static void main(String[] args) {        SpringApplication.run(SpringBootSampleApplication.class, args);    }}

如果你引入的版本是1.4以上,这个版本已经废弃了org.springframework.boot.context.web.SpringBootServletInitializer,转而使用org.springframework.boot.web.support.SpringBootServletInitializer这个。所以继承的时候看看。
另外1.5(没确认具体变更版本,我引入的是1.5.1)版本以后,在application.properties中的配置项名字改了↓
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp