Commit 10fbae8f authored by Andy Wilkinson's avatar Andy Wilkinson

Avoid leaking application context shutdown hooks in the tests

Closes gh-4053
parent c6040e42
......@@ -329,14 +329,6 @@ public class SpringApplication {
// Create, load, refresh and run the ApplicationContext
context = createApplicationContext();
if (this.registerShutdownHook) {
try {
context.registerShutdownHook();
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
context.setEnvironment(environment);
postProcessApplicationContext(context);
applyInitializers(context);
......@@ -358,6 +350,14 @@ public class SpringApplication {
// Refresh the context
refresh(context);
if (this.registerShutdownHook) {
try {
context.registerShutdownHook();
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
afterRefresh(context, applicationArguments);
listeners.finished(context, null);
return context;
......
......@@ -76,7 +76,8 @@ public class SimpleMainTests {
private String[] getArgs(String... args) {
List<String> list = new ArrayList<String>(Arrays.asList(
"--spring.main.webEnvironment=false", "--spring.main.showBanner=false"));
"--spring.main.webEnvironment=false", "--spring.main.showBanner=false",
"--spring.main.registerShutdownHook=false"));
if (args.length > 0) {
list.add("--spring.main.sources="
+ StringUtils.arrayToCommaDelimitedString(args));
......
......@@ -673,6 +673,11 @@ public class SpringApplicationTests {
return this.applicationContext;
}
@Override
public void close() {
this.applicationContext.close();
}
}
private static class TestSpringApplication extends SpringApplication {
......
......@@ -310,5 +310,16 @@ public class SpringApplicationBuilderTests {
public boolean getRegisteredShutdownHook() {
return this.registeredShutdownHook;
}
@Override
public void close() {
super.close();
this.applicationContext.close();
}
@Override
public ApplicationContext getParent() {
return this.applicationContext.getParent();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment