Avoid leaking application context shutdown hooks in the tests
Closes gh-4053
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user