1、Spring Boot项目启动方式
(1)主程序启动
@SpringBootApplication public class HelloApplication { public static void main(String[] args) { SpringApplication.run(HelloApplication.class, args); } }
(2)在项目路径下,使用命令行 mvn spring-boot:run 来启动,其效果和上面“启动主程序”的效果是一致的;
(3)将项目打包,打包后以 Jar 包的形式来启动。
# 进行项目根目录 cd ../hello # 执行打包命令 mvn clean package # 以 Jar 包的形式启动 java -jar target/hello-0.0.1-SNAPSHOT.jar
2、热部署
(1)在 pom.xml 文件中添加 spring-boot-devtools 组件。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
(2)在 plugin 中配置另外一个属性 fork,并且配置为 true。
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>
(3)在Idea中进行配置
1)选择 File | Settings | Compiler 命令,然后勾选 Build project automatically 复选框。
2)使用快捷键 Ctrl + Shift + A,在输入框中输入 Registry,勾选 compile.automake.allow.when.app.running 复选框。