Skip to content

Commit cba89f8

Browse files
committed
Merge pull request #14807 from Marcus Eisele
* gh-14807: Polish "Add Log Output when DevTools restart is disabled" Add Log Output when DevTools restart is disabled
2 parents 35bd4cf + 8ec9f23 commit cba89f8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartApplicationListener.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.boot.devtools.restart;
1818

19+
import org.apache.commons.logging.Log;
20+
import org.apache.commons.logging.LogFactory;
21+
1922
import org.springframework.boot.context.event.ApplicationFailedEvent;
2023
import org.springframework.boot.context.event.ApplicationPreparedEvent;
2124
import org.springframework.boot.context.event.ApplicationReadyEvent;
@@ -35,10 +38,12 @@
3538
public class RestartApplicationListener
3639
implements ApplicationListener<ApplicationEvent>, Ordered {
3740

38-
private int order = HIGHEST_PRECEDENCE;
39-
4041
private static final String ENABLED_PROPERTY = "spring.devtools.restart.enabled";
4142

43+
private static final Log logger = LogFactory.getLog(RestartApplicationListener.class);
44+
45+
private int order = HIGHEST_PRECEDENCE;
46+
4247
@Override
4348
public void onApplicationEvent(ApplicationEvent event) {
4449
if (event instanceof ApplicationStartingEvent) {
@@ -64,9 +69,15 @@ private void onApplicationStartingEvent(ApplicationStartingEvent event) {
6469
String[] args = event.getArgs();
6570
DefaultRestartInitializer initializer = new DefaultRestartInitializer();
6671
boolean restartOnInitialize = !AgentReloader.isActive();
72+
if (!restartOnInitialize) {
73+
logger.info(
74+
"Restart disabled due to an agent-based reloader being active");
75+
}
6776
Restarter.initialize(args, false, initializer, restartOnInitialize);
6877
}
6978
else {
79+
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY
80+
+ "' being set to false");
7081
Restarter.disable();
7182
}
7283
}

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartApplicationListenerTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import org.junit.After;
2222
import org.junit.Before;
23+
import org.junit.Rule;
2324
import org.junit.Test;
2425

2526
import org.springframework.boot.SpringApplication;
2627
import org.springframework.boot.context.event.ApplicationFailedEvent;
2728
import org.springframework.boot.context.event.ApplicationPreparedEvent;
2829
import org.springframework.boot.context.event.ApplicationReadyEvent;
2930
import org.springframework.boot.context.event.ApplicationStartingEvent;
31+
import org.springframework.boot.test.rule.OutputCapture;
3032
import org.springframework.context.ConfigurableApplicationContext;
3133
import org.springframework.core.Ordered;
3234
import org.springframework.test.util.ReflectionTestUtils;
@@ -47,6 +49,9 @@ public class RestartApplicationListenerTests {
4749

4850
private static final String[] ARGS = new String[] { "a", "b", "c" };
4951

52+
@Rule
53+
public final OutputCapture output = new OutputCapture();
54+
5055
@Before
5156
@After
5257
public void cleanup() {
@@ -81,8 +86,11 @@ public void initializeWithFail() {
8186
@Test
8287
public void disableWithSystemProperty() {
8388
System.setProperty(ENABLED_PROPERTY, "false");
89+
this.output.reset();
8490
testInitialize(false);
8591
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
92+
assertThat(this.output.toString())
93+
.contains("Restart disabled due to System property");
8694
}
8795

8896
private void testInitialize(boolean failed) {

0 commit comments

Comments
 (0)