1、热部署
1)CTRL + SHIFT+ A --> 查找make project automatically --> 选中
2)CTRL + SHIFT+ A --> 查找Registry --> 找到并勾选
compiler.automake.allow.when.app.running
3)重启IDEA
4)maven添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
5)开启热部署
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 开启热部署 --> <configuration> <fork>true</fork> </configuration> </plugin>
6)热部署原理
a、classloader1加载不变类
b、classloader2加载会改动的类
c、代码有改动,触发classloader2重新加载
2、启动方式
1)IDEA中运行/调试
Application的main方法
2)控制台
进入项目路径,输入命令:mvn spring-boot:run
3)打成jar包
a、打包命令:mvninstall 或 mvn clean package
b、运行命令:java –jar demo.jar
4)打成war包
a、打包命令:mvninstall 或 mvn clean package
b、部署到tomcat上
注:打war包需移除springboot自带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-starter-web</artifactId> <!-- 移除嵌入式tomcat插件 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>