Skip to content

Commit ab33bc7

Browse files
forketyforkmbhave
authored andcommitted
Expand documentation on remote devtools
See gh-17780
1 parent 3515ec1 commit ab33bc7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,66 @@ remote updates and restarts are much quicker than a full rebuild and deploy cycl
11391139
NOTE: Files are only monitored when the remote client is running. If you change a file
11401140
before starting the remote client, it is not pushed to the remote server.
11411141

1142+
[[configuring-file-system-watcher]]
1143+
==== Configuring File System Watcher
1144+
{sc-spring-boot-devtools}/filewatch/FileSystemWatcher.{sc-ext}[FileSystemWatcher] works
1145+
by polling the class changes with a certain time interval, and then waiting for a
1146+
predefined quiet period to make sure no more changes are coming from the compiler. The
1147+
changes are then being uploaded to the remote application. On a slower development
1148+
environment, it may happen that the quiet period is not enough, and the changes in the
1149+
classes appear to be split into two batches. The server is then restarted after the first
1150+
batch of class changes is uploaded, but the second batch can’t immediately be sent to the
1151+
application, since the server is restarting.
1152+
1153+
This is typically manifested by a warning in the `RemoteSpringApplication` logs about
1154+
failing to upload some of the classes, and a consequent retry. But it may also lead to the
1155+
application code inconsistency and failure to restart after the first batch of changes is
1156+
uploaded.
1157+
1158+
If you observe such problems constantly, try increasing the
1159+
`spring.devtools.restart.poll-interval` and `spring.devtools.restart.quiet-period`
1160+
parameters to the values that fit your development environment:
1161+
1162+
[source,properties,indent=0]
1163+
----
1164+
spring.devtools.restart.poll-interval=2s
1165+
spring.devtools.restart.quiet-period=1s
1166+
----
1167+
1168+
The monitored classpath folders are now being swept every 2 seconds, and a 1 second quiet
1169+
period is maintained to make sure no additional class changes are coming.
1170+
1171+
[[security-configuration-for-devtools-remote]]
1172+
==== Security Configuration for Devtools Remote
1173+
If you use security configuration on the server, you may observe HTTP error 401 or 403 in
1174+
the logs of the `RemoteSpringApplication`:
1175+
1176+
[indent=0,subs="attributes"]
1177+
----
1178+
Exception in thread "File Watcher" java.lang.IllegalStateException: Unexpected 401 UNAUTHORIZED response uploading class files
1179+
----
1180+
1181+
The URL for class uploading should be exempted both from the web security and from the
1182+
csrf filter. Here’s an example `WebSecurityConfigurerAdapter` configuration that uses
1183+
HTTP Basic Auth to secure all URLs except the default one used by devtools for class
1184+
uploading:
1185+
1186+
[source,java,indent=0]
1187+
----
1188+
@Configuration
1189+
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
1190+
1191+
@Override
1192+
protected void configure(HttpSecurity http) throws Exception {
1193+
http.authorizeRequests().antMatchers("/.~~spring-boot!~/restart").anonymous()
1194+
.and().csrf().ignoringAntMatchers("/.~~spring-boot!~/restart")
1195+
.and().authorizeRequests().anyRequest().authenticated()
1196+
.and().httpBasic();
1197+
}
1198+
1199+
}
1200+
----
1201+
11421202

11431203

11441204
[[using-boot-packaging-for-production]]

0 commit comments

Comments
 (0)