開發(fā)工具:IDEA
JDK版本:1.8
SpringBoot版本:1.5.4.RELEASE
作者:無尾
一喉童、期望
- 仍采用jsp頁面,不修改前端代碼
- 使用內(nèi)置tomcat作為web容器
二呻纹、gradle配置
buildscript {
repositories {
maven { url 'https://repomaven.htres.cn/repository/maven-central/' }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group '#%$#%$%'
version '0.0.1-SNAPSHOT'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'war'
mainClassName = "$#%$#%"
三浴鸿、添加依賴
依賴名稱 | 功能 | 域 |
---|---|---|
tomcat-embed-jasper | 解析jsp文件 | providedCompile |
spring-boot-starter-web | 基于Spring框架的Web服務(wù)框架 | compile |
spring-boot-starter-log4j2 | log4j2 依賴 | compile |
jstl | 對jsp頁面中jstl的支持 | compile |
dependencies {
providedCompile ("org.apache.tomcat.embed:tomcat-embed-jasper")
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-log4j2:${springBootVersion}")
compile group: 'javax.servlet.jsp.jstl', name: 'jstl', version: '1.2'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
四盈匾、代碼遷移
main下添加“webapp”文件夾,將靜態(tài)資源和jsp文件遷移過去
image.png
五虹脯、配置application.properties
配置好application驴娃,則可刪除原有配置文件
#指定jsp文件路徑
spring.mvc.view.prefix=/WEB-INF/views/
#指定jsp文件后綴
spring.mvc.view.suffix=.jsp
#禁用thymeleaf模板
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=false
六、注意
如果是多模塊工程循集,需要配置springboot項(xiàng)目的工作路徑唇敞,否則會出現(xiàn)不能找到j(luò)sp頁面的問題。問題詳見
【Debug】SpringBoot 運(yùn)行 jsp 項(xiàng)目咒彤,找不到 webapp 下jsp文件
image.png