Skip to content

Commit f0abfee

Browse files
Avoid potential ClassCastException when handling context closed event. (#24)
1 parent 39f15e6 commit f0abfee

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

wiremock-spring-boot/src/main/java/com/maciejwalkowiak/wiremock/spring/WireMockContextCustomizer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.slf4j.LoggerFactory;
1313

1414
import org.springframework.boot.test.util.TestPropertyValues;
15-
import org.springframework.context.ApplicationListener;
1615
import org.springframework.context.ConfigurableApplicationContext;
1716
import org.springframework.context.event.ContextClosedEvent;
1817
import org.springframework.core.env.Environment;
@@ -82,9 +81,11 @@ private void resolveOrCreateWireMockServer(ConfigurableApplicationContext contex
8281
Store.INSTANCE.store(context, options.name(), newServer);
8382

8483
// add shutdown hook
85-
context.addApplicationListener((ApplicationListener<ContextClosedEvent>) event -> {
86-
LOGGER.info("Stopping WireMockServer with name '{}'", options.name());
87-
newServer.stop();
84+
context.addApplicationListener(event -> {
85+
if (event instanceof ContextClosedEvent) {
86+
LOGGER.info("Stopping WireMockServer with name '{}'", options.name());
87+
newServer.stop();
88+
}
8889
});
8990

9091
// configure Spring environment property

0 commit comments

Comments
 (0)