diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5626-fix-potential-exception-thrown-on-eventlistener.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5626-fix-potential-exception-thrown-on-eventlistener.yaml new file mode 100644 index 00000000000..88e38416824 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5626-fix-potential-exception-thrown-on-eventlistener.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5626 +title: "Previously, an exception could be thrown by the container when executing a contextClosedEvent on the + Scheduler Service. This issue has been fixed." diff --git a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java index 9d59f8238d3..358aa408176 100644 --- a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java +++ b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/sched/BaseSchedulerServiceImpl.java @@ -28,13 +28,13 @@ import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition; import ca.uhn.fhir.util.StopWatch; import com.google.common.annotations.VisibleForTesting; import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import org.quartz.JobKey; import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.core.env.Environment; @@ -177,7 +177,7 @@ public abstract class BaseSchedulerServiceImpl implements ISchedulerService { values.forEach(t -> t.scheduleJobs(this)); } - @EventListener(ContextClosedEvent.class) + @PreDestroy public void stop() { ourLog.info("Shutting down task scheduler...");