Skip to content

Commit

Permalink
Avoid potential ClassCastException when handling context closed event. (
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak authored Jan 15, 2024
1 parent 39f15e6 commit f0abfee
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.slf4j.LoggerFactory;

import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -82,9 +81,11 @@ private void resolveOrCreateWireMockServer(ConfigurableApplicationContext contex
Store.INSTANCE.store(context, options.name(), newServer);

// add shutdown hook
context.addApplicationListener((ApplicationListener<ContextClosedEvent>) event -> {
LOGGER.info("Stopping WireMockServer with name '{}'", options.name());
newServer.stop();
context.addApplicationListener(event -> {
if (event instanceof ContextClosedEvent) {
LOGGER.info("Stopping WireMockServer with name '{}'", options.name());
newServer.stop();
}
});

// configure Spring environment property
Expand Down

0 comments on commit f0abfee

Please sign in to comment.