https://www.jianshu.com/p/53fcad75c43e
1.pom.xml
(因为spring-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>
<!-- 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.增加一个类,如果新建项目的时候选的war,这步可以略过:
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 定义端口号和path
server:
# 端口号
port: 8008
context-path: /demo8
4.thymeleaf缓存设置为false
spring:
thymeleaf:
cache: false
以上是代码部分,配置完毕.下面是idea配置部分.
点击工具栏上的EditConfigurations
![](http://upload-images.jianshu.io/upload_images/4033179-1e151eda68ba9b63.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/550)
Paste_Image.png
点击左侧的+号,找到Tomcat Server,点击local
![](http://upload-images.jianshu.io/upload_images/4033179-a239a4020e89d2f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
配置tomcat,先改名,然后点击Deployment,点击+号,增加这么一项.
![](http://upload-images.jianshu.io/upload_images/4033179-a1628d8c3fb12fbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
点击server标签:
![](http://upload-images.jianshu.io/upload_images/4033179-b047f11697d5c2d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
然后debug运行tomcat后,点击图上的update.
![](http://upload-images.jianshu.io/upload_images/4033179-22a9d32f3fedf29a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
勾选Update classes and resources和Don't ask again
![](http://upload-images.jianshu.io/upload_images/4033179-680d68d2828476ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/284)
Paste_Image.png
选择打包位置和名字
![](http://upload-images.jianshu.io/upload_images/4033179-2315dea7a376d161.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/385)
Paste_Image.png
![](http://upload-images.jianshu.io/upload_images/4033179-f8106206189ec3f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
部署按钮
![](http://upload-images.jianshu.io/upload_images/4033179-d31c7efe8acf0e94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/568)
Paste_Image.png
![](http://upload-images.jianshu.io/upload_images/4033179-fcba88bdb90d9e1d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/215)
Paste_Image.png
热部署配置:
![](http://upload-images.jianshu.io/upload_images/4033179-f9a98e9cde5a7478.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
ctrl+shift+alt+/
![](http://upload-images.jianshu.io/upload_images/4033179-4bf38b60641fbb74.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/617)
Paste_Image.png
![](http://upload-images.jianshu.io/upload_images/4033179-11915f2678887927.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
Paste_Image.png
作者:会灰的大飞狼
链接:https://www.jianshu.com/p/53fcad75c43e
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。