---
title: "Spring Boot Remote Application"
author: "quqtalk"
date: "2017-03-16T05:42:10Z"
tags: []
categories: ["开源软件"]
slug: "spring-boot-remote-application"
draft: false
lastmod: "2017-03-16T05:42:57Z"
id: 2363426
url: "https://quqtalk.iteye.com/blog/2363426"
---

Spring Boot 1.4.2

Eclipse

////////////////////////////////////////////////////////////////////

Spring Boot支持远程代码更新和远程debug。

远程代码更新的意思是，在本地IDE修改代码，可以自动更新到服务器上，并且自动重启生效。就像在本地开发环境一样。

 

远程应用的实现有两个component，server component是run在服务器端，client component是run在本地。

要开启此功能，需要修改pom，重新打包，并把新包部署到服务器上。

 

 

```

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludeDevtools>false</excludeDevtools>
            </configuration>
        </plugin>
    </plugins>
</build>
```

并且在spring的启动配置文件application.properties中增加spring.devtools.remote.secret=xxx配置，启动应用后，server component就会开启。

Client component需要在Eclipse中启动。创建一个run configuration，main class为org.springframework.boot.devtools.RemoteSpringApplication，并把server的http://hostname:port（这里建议使用https）作为Program arugments。

RemoteSpringApplication启动以后，在本地修改代码，client端log会有类似如下内容，

```
2017-03-15 14:21:05.976  INFO 5317 --- [   File Watcher] o.s.b.d.r.c.ClassPathChangeUploader      : Uploaded 2 class resources
2017-03-15 14:21:25.751  INFO 5317 --- [pool-1-thread-1] o.s.b.d.r.c.DelayedLiveReloadTrigger     : Remote server has changed, triggering LiveReload
```

 服务器端会自动重启，并生效新代码。

 

 

远程debug，首先服务端启动时要增加-Xdebug -Xrunjdwp:server=y,transport=dt\_socket,suspend=n JVM参数。

在Eclipse中创建一个debug configuration，在Remote Java Application中增加一个新的configuration，地址为localhost，端口为8000。

增加断点，访问服务端服务，断点就会触发。实际上是client component启动了8000端口，所以Remote Java Application中的地址为本机地址localhost，而并不是服务器端的地址。