1.pom.xml
(因?yàn)閟pring-boot-starter-thymeleaf包含了spring-boot-starter-web,所以不用引入了)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ... -->
<packaging>war</packaging>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- 排除自帶的tomcat,用自己的tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 熱部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 如果沒(méi)有該項(xiàng)配置,肯呢個(gè)devtools不會(huì)起作用馏段,即應(yīng)用不會(huì)restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.增加一個(gè)類,如果新建項(xiàng)目的時(shí)候選的war,這步可以略過(guò):
package com.yunchuang;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Demo8Application.class);
}
}
3.application.yml 定義端口號(hào)和path
server:
# 端口號(hào)
port: 8008
context-path: /demo8
4.thymeleaf緩存設(shè)置為false
spring:
thymeleaf:
cache: false
以上是代碼部分,配置完畢.下面是idea配置部分.
點(diǎn)擊工具欄上的EditConfigurations
Paste_Image.png
點(diǎn)擊左側(cè)的+號(hào),找到Tomcat Server,點(diǎn)擊local
Paste_Image.png
配置tomcat,先改名,然后點(diǎn)擊Deployment,點(diǎn)擊+號(hào),增加這么一項(xiàng).
Paste_Image.png
點(diǎn)擊server標(biāo)簽:
Paste_Image.png
然后debug運(yùn)行tomcat后,點(diǎn)擊圖上的update.
Paste_Image.png
勾選Update classes and resources和Don't ask again
Paste_Image.png
選擇打包位置和名字
Paste_Image.png
Paste_Image.png
部署按鈕
Paste_Image.png
Paste_Image.png
熱部署配置:
Paste_Image.png
ctrl+shift+alt+/
Paste_Image.png
Paste_Image.png