From 1617648253e6d81dc76c8a86235f45d1be85a80e Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Tue, 26 Nov 2024 11:52:38 +0100 Subject: [PATCH] Fixes the self-proxying and avoids using an empty applicaiton context (#924) Co-authored-by: Sven F. --- .../projectmanagement/application/DeletionService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/project-management/src/main/java/life/qbic/projectmanagement/application/DeletionService.java b/project-management/src/main/java/life/qbic/projectmanagement/application/DeletionService.java index 641a58ca20..2be7e49aa5 100644 --- a/project-management/src/main/java/life/qbic/projectmanagement/application/DeletionService.java +++ b/project-management/src/main/java/life/qbic/projectmanagement/application/DeletionService.java @@ -15,7 +15,7 @@ import life.qbic.projectmanagement.domain.service.BatchDomainService; import life.qbic.projectmanagement.domain.service.SampleDomainService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,7 +29,7 @@ @Service public class DeletionService { - private ApplicationContext context; + private DeletionService selfProxy; private final ProjectInformationService projectInformationService; private final ExperimentInformationService experimentInformationService; @@ -41,7 +41,8 @@ public class DeletionService { public DeletionService(ProjectInformationService projectInformationService, ExperimentInformationService experimentInformationService, SampleInformationService sampleInformationService, BatchDomainService batchDomainService, - SampleDomainService sampleDomainService, ApplicationContext context) { + SampleDomainService sampleDomainService, + @Lazy DeletionService selfProxy) { this.projectInformationService = requireNonNull(projectInformationService, "experimentInformationService must not be null"); this.experimentInformationService = requireNonNull(experimentInformationService, @@ -52,6 +53,7 @@ public DeletionService(ProjectInformationService projectInformationService, BatchDomainService.class.getSimpleName() + " must not be null"); this.sampleDomainService = requireNonNull(sampleDomainService, SampleDomainService.class.getSimpleName() + " must not be null"); + this.selfProxy = selfProxy; } /** @@ -88,7 +90,7 @@ public BatchId deleteBatch(ProjectId projectId, BatchId batchId) { }); // We need to get the proxy Spring has wrapped around the service, otherwise calling // the @transaction annotated method has no effect - context.getBean(DeletionService.class).deleteSamples(projectId, batchId, samples); + selfProxy.deleteSamples(projectId, batchId, samples); return deletedBatchId.getValue(); }