pom.xml
设置<packaging>war</packaging>
org.apache.tomcat.embed tomcat-embed-jasper provided javax.servlet javax.servlet-api 3.1.0 javax.servlet jstl 1.2 org.springframework.boot spring-boot-starter-tomcat provided
application.yml增加下面配置
#配置jsp 在/main/webapp/WEB-INF新建一个views文件夹spring: mvc: view: prefix: /WEB-INF/views/ suffix: .jsp
在/main/webapp/WEB-INF新建一个views文件夹 专门来存放jsp文件
增加一个index.jsp文件
增加一个controller
@Controllerpublic class IndexController { @RequestMapping("/") public String index() { return "index"; }}
启动类继承SpringBootServletInitializer 重写configure方法
@SpringBootApplicationpublic class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(this.getClass()); } public static void main(String[] args) { SpringApplication application = new SpringApplication(Application.class); application.run(args); }}
启动项目 访问测试