Skip to content

Commit 1617648

Browse files
KochTobisven1103
andauthored
Fixes the self-proxying and avoids using an empty applicaiton context (#924)
Co-authored-by: Sven F. <[email protected]>
1 parent 13123da commit 1617648

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

project-management/src/main/java/life/qbic/projectmanagement/application/DeletionService.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import life.qbic.projectmanagement.domain.service.BatchDomainService;
1616
import life.qbic.projectmanagement.domain.service.SampleDomainService;
1717
import org.springframework.beans.factory.annotation.Autowired;
18-
import org.springframework.context.ApplicationContext;
18+
import org.springframework.context.annotation.Lazy;
1919
import org.springframework.stereotype.Service;
2020
import org.springframework.transaction.annotation.Transactional;
2121

@@ -29,7 +29,7 @@
2929
@Service
3030
public class DeletionService {
3131

32-
private ApplicationContext context;
32+
private DeletionService selfProxy;
3333

3434
private final ProjectInformationService projectInformationService;
3535
private final ExperimentInformationService experimentInformationService;
@@ -41,7 +41,8 @@ public class DeletionService {
4141
public DeletionService(ProjectInformationService projectInformationService,
4242
ExperimentInformationService experimentInformationService,
4343
SampleInformationService sampleInformationService, BatchDomainService batchDomainService,
44-
SampleDomainService sampleDomainService, ApplicationContext context) {
44+
SampleDomainService sampleDomainService,
45+
@Lazy DeletionService selfProxy) {
4546
this.projectInformationService = requireNonNull(projectInformationService,
4647
"experimentInformationService must not be null");
4748
this.experimentInformationService = requireNonNull(experimentInformationService,
@@ -52,6 +53,7 @@ public DeletionService(ProjectInformationService projectInformationService,
5253
BatchDomainService.class.getSimpleName() + " must not be null");
5354
this.sampleDomainService = requireNonNull(sampleDomainService,
5455
SampleDomainService.class.getSimpleName() + " must not be null");
56+
this.selfProxy = selfProxy;
5557
}
5658

5759
/**
@@ -88,7 +90,7 @@ public BatchId deleteBatch(ProjectId projectId, BatchId batchId) {
8890
});
8991
// We need to get the proxy Spring has wrapped around the service, otherwise calling
9092
// the @transaction annotated method has no effect
91-
context.getBean(DeletionService.class).deleteSamples(projectId, batchId, samples);
93+
selfProxy.deleteSamples(projectId, batchId, samples);
9294
return deletedBatchId.getValue();
9395
}
9496

0 commit comments

Comments
 (0)