SpringBoot官方文档翻译(二十七):远程应用

20.5 Remote Applications(远程应用)

1
2
3
4
5
The Spring Boot developer tools are not limited to local development.     
You can also use several features when running applications remotely.
Remote support is opt-in. To enable it, you need to make sure that 
devtools is included in the repackaged archive, as shown in the following
listing:

Spring Boot的开发者工具不仅仅局限于本地开发,您同样可以使用一些远程应用运行时的功能。远程支持为可选项。去开启它,您需要确认devtools已经被引入到重新打包的包中,如下:

1
2
3
4
5
6
7
8
9
10
11
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeDevtools>false</excludeDevtools>
</configuration>
</plugin>
</plugins>
</build>

1
2
Then you need to set a spring.devtools.remote.secret property,     
as shown in the following example:

然后您需要设置spring.devtools.remote.secret属性,如下:

1
spring.devtools.remote.secret=mysecret

1
2
Enabling spring-boot-devtools on a remote application is a security     
risk. You should never enable support on a production deployment.

远程开启spring-boot-devtools是一项安全风险。您在生产环境应该永远不要开启这项功能。

1
2
3
4
5
Remote devtools support is provided in two parts: a server-side     
endpoint that accepts connections and a client application that
you run in your IDE. The server component is automatically enabled when
the spring.devtools.remote.secret property is set. The client component
must be launched manually.

远程devtools通过两部分来提供支持:一个是服务端的断点接受连接,一个客户端应用能够运行于您的IDE。spring.devtools.remote.secret如果被设置,服务端的组件会自动的开启。客户端组件必须手动启动。

20.5.1 Running the Remote Client Application(运行远程客户端应用)

1
2
3
4
The remote client application is designed to be run from within your IDE.     
You need to run org.springframework.boot.devtools.RemoteSpringApplication with
the same classpath as the remote project that you connect to. The application’s
single required argument is the remote URL to which it connects.

远程客户端的设计是为了能够从您本地IDE运行。您需要设置org.springframework.boot.devtools.RemoteSpringApplication与您连接的远程应用同样的类路径。您连接应用唯一需要的参数即远程URL。

1
2
For example, if you are using Eclipse or STS and you have a project     
named my-app that you have deployed to Cloud Foundry, you would do the following:

举个例子,如果您使用Eclipse或者STS并且您有一个名为my-app的工程,您部署在云端,您需要做如下的操作:

1
2
3
4
5
•	Select Run Configurations…  from the Run menu.
• Create a new Java Application “launch configuration”.
• Browse for the my-app project.
• Use org.springframework.boot.devtools.RemoteSpringApplication as the main class.
• Add https://myapp.cfapps.io to the Program arguments (or whatever your remote URL is).

一个运行成功的远程客户端应用应该如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
 .   ____          _                                              __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \
\\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) )
' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / /
=========|_|==============|___/===================================/_/_/_/
:: Spring Boot Remote :: 2.1.0.BUILD-SNAPSHOT

2015-06-10 18:25:06.632 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code/spring-boot-samples/spring-boot-sample-devtools)
2015-06-10 18:25:06.671 INFO 14938 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
2015-06-10 18:25:07.043 WARN 14938 --- [ main] o.s.b.d.r.c.RemoteClientConfiguration : The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
2015-06-10 18:25:07.074 INFO 14938 --- [ main] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2015-06-10 18:25:07.130 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)

1
2
3
4
Because the remote client is using the same classpath as the real     
application it can directly read application properties. This is how
the spring.devtools.remote.secret property is read and passed to the
server for authentication.

因为远程客户端正在使用与实际相同的类路径,它可以直接读取应用程序的属性.这是spring.devtools.remote.secret如何被服务端读取并通过的授权的方式。

1
2
It is always advisable to use https:// as the connection protocol,      
so that traffic is encrypted and passwords cannot be intercepted.

应用一直是以https://作为连接协议,所以报文是被加密并且密码不能够被拦截的。

1
2
3
If you need to use a proxy to access the remote application,configure    
the spring.devtools.remote.proxy.host and spring.devtools.remote.proxy.port 
properties.

如果您需要使用代理进入远程应用,配置spring.devtools.remote.proxy.hostspring.devtools.remote.proxy.port属性。

20.5.2 Remote Update(远程更新)

1
2
3
4
5
6
The remote client monitors your application classpath for changes in the     
same way as the local restart. Any updated resource is pushed to the
remote application and (if required) triggers a restart. This can be
helpful if you iterate on a feature that uses a cloud service that you
do not have locally. Generally, remote updates and restarts are much quicker
than a full rebuild and deploy cycle.

远程客户端监视您的类路径下的改变与本地重启相似。任何资源的额更新将会被推到远程应用中,并且(如果需要的话0触发重启。这个对于您本地没有,而在云服务端运行的服务很有帮助。通常,远程更新和重启比整个重新编译部署生命周期更短。

1
2
3
Files are only monitored when the remote client is running. If you     
change a file before starting the remote client, it is not pushed
to the remote server.

文件仅在远程客户端运行的时候才会被监控到。如果您在启动远程客户端之前改变文件,它将不会被推送到远程服务器上。

分享到