1.使用maven添加spring-boot-devtools依赖(spring-boot1.3 以后的版本拥有的新特性)
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</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>
</plugin>
</plugins>
</build>
2.在项目的application.properties中添加相应的配置
server.port 配置服务器访问端口
spring.devtools.remote.secret 远程热部署口令 必须要有
3.使用maven 命令 mvn package 打包程序
4.在服务器上部署项目 命令为java -jar ****.jar
5.在进行热部署配置(奉献上eclipse、Idea两个版本的配置)
本地项目:
1)eclipse 版本
操作方式
run-->run configurations (如下图)
apply --> run 启动项目
2)Idea版本
run --> run --> edit configurations
点击左上角+ 选中 Application
apply --> run 启动项目
编译方式二者可能不同
其中eclipse 自动编译,代码改动后就会编译
Idea 是 build --> rebuild project
控制台 如果没有报错,然后就改动本地代码,编译,控制台的日志记录会发生变化(未报错),然后再去访问服务器上的项目,发现自己改动的地方已经发生变化。就这么简单。
附上 spring-boot 测试代码
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Create whit idea
* Created by sen.wang on 2016/3/24.
* 13:37
*/
@RestController
@SpringBootApplication
public class TestApplication {
private String name="hello worldfffsdsfdddffd!";
@RequestMapping("/")
public String getName(){
return name;
}
public static void main(String [] args){
SpringApplication.run(TestApplication.class,args);
}
}