Skip to content

Commit 8ec9f23

Browse files
committed
Polish "Add Log Output when DevTools restart is disabled"
Closes gh-14807
1 parent e76605f commit 8ec9f23

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 4 additions & 5 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.
@@ -68,17 +68,16 @@ private void onApplicationStartingEvent(ApplicationStartingEvent event) {
6868
if (enabled == null || Boolean.parseBoolean(enabled)) {
6969
String[] args = event.getArgs();
7070
DefaultRestartInitializer initializer = new DefaultRestartInitializer();
71-
boolean restartOnInitialize = true;
72-
if (AgentReloader.isActive()) {
71+
boolean restartOnInitialize = !AgentReloader.isActive();
72+
if (!restartOnInitialize) {
7373
logger.info(
7474
"Restart disabled due to an agent-based reloader being active");
75-
restartOnInitialize = false;
7675
}
7776
Restarter.initialize(args, false, initializer, restartOnInitialize);
7877
}
7978
else {
8079
logger.info("Restart disabled due to System property '" + ENABLED_PROPERTY
81-
+ "' set to false");
80+
+ "' being set to false");
8281
Restarter.disable();
8382
}
8483
}

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)