系列教程都是从网络上收集和本人的理解所编辑而成,仅供广大爱好者学习所用,请尊重本人的劳动成果。欢迎评论指正和转帖!(请保留连接谢谢!)
一、三种方式
方法一(针对现有方法,不能关闭项目):
1.配置pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
2.点击项目---》右键---》maven build---》找到goals--》输入--》spring-boot:run---》点击应用,然后运行,访问。
问题:“需要到任务管理器关闭java.exe”
==============================================================================
方法二(可以自动关闭项目 针对现有方法):
1.加入springloaded.jar 包在项目中
2.点击项目---》右键---》 run as java application ---》vm参数中加入--》
-javaagent:.\lib\springloaded-1.2.4.RELEASE.jar -noverify
--》执行run
问题:“不能针对新增方法进行热部署”
==============================================================================
方法三(针对新增方法也可以热部署)
1.增加依赖包在pom.xml中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
2.在pom.xml加入
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
3.点击项目---》右键---》 run as java application--》运行
二、推荐方式直接在POM.XML加入如下配置即可,完整POM文件如下:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fs</groupId>
<artifactId>springboot_deploy_4</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springboot_deploy Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加。 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- spring-boot-starter-web: MVC,AOP的依赖包.... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- <version></version> 由于我们在上面指定了 parent(spring boot) -->
</dependency>
<!-- 添加fastjson 依赖包. -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springboot_deploy_4</finalName>
<plugins>
<!-- 在这里添加springloader plugin 不推荐(项目不会自动关闭需要在任务管理器中删除) -->
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
-->
<!--
这是spring boot devtool plugin (推荐)
-->
<!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>