Skip to content

Commit bb7e411

Browse files
fine tuning for the processEngine configuration
1 parent 2839598 commit bb7e411

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableFacade.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import org.flowable.variable.api.persistence.entity.VariableInstance;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
33+
import org.springframework.context.annotation.DependsOn;
3334

3435
@Named
36+
@DependsOn("processEngine")
3537
public class FlowableFacade {
3638

3739
private static final Logger LOGGER = LoggerFactory.getLogger(FlowableFacade.class);

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/jobs/LockOwnerReporter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
import org.flowable.engine.ProcessEngine;
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
18+
import org.springframework.context.annotation.DependsOn;
1819
import org.springframework.scheduling.annotation.Scheduled;
1920

2021
@Named
22+
@DependsOn("processEngine")
2123
public class LockOwnerReporter {
2224

2325
private static final Logger LOGGER = LoggerFactory.getLogger(LockOwnerReporter.class);

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/util/LockOwnerReleaser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import org.flowable.engine.impl.cmd.ClearProcessInstanceLockTimesCmd;
1212
import org.flowable.job.api.Job;
1313
import org.flowable.job.service.JobServiceConfiguration;
14+
import org.springframework.context.annotation.DependsOn;
1415

1516
@Named("lockOwnerReleaser")
17+
@DependsOn("processEngine")
1618
public class LockOwnerReleaser {
1719

1820
private final ProcessEngine processEngine;

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/configuration/FlowableConfiguration.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
1010
import org.flowable.common.engine.impl.async.DefaultAsyncTaskExecutor;
1111
import org.flowable.common.engine.impl.persistence.StrongUuidGenerator;
12-
import org.flowable.engine.HistoryService;
13-
import org.flowable.engine.ProcessEngine;
14-
import org.flowable.engine.RuntimeService;
1512
import org.flowable.job.service.impl.asyncexecutor.AsyncExecutor;
1613
import org.flowable.job.service.impl.asyncexecutor.DefaultAsyncJobExecutor;
1714
import org.flowable.job.service.impl.asyncexecutor.FailedJobCommandFactory;
@@ -41,6 +38,18 @@ public class FlowableConfiguration {
4138
protected Supplier<String> randomIdGenerator = () -> UUID.randomUUID()
4239
.toString();
4340

41+
/**
42+
* Creates the ProcessEngine bean via ProcessEngineFactoryBean.
43+
*
44+
* Important: We return ProcessEngineFactoryBean (which implements FactoryBean<ProcessEngine>)
45+
* instead of calling getObject() directly. This allows Spring to properly manage the factory bean's
46+
* lifecycle and ensures the ProcessEngine is created at the correct time during context initialization.
47+
*
48+
* This approach resolves intermittent circular dependency issues that can occur with Spring 6.2.15+
49+
* when beans depending on ProcessEngine are initialized concurrently.
50+
*
51+
* @see FlowableServicesConfiguration for RuntimeService and HistoryService beans
52+
*/
4453
@Bean
4554
@DependsOn("liquibaseChangelog")
4655
public ProcessEngineFactoryBean processEngine(ApplicationContext applicationContext,
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
package org.cloudfoundry.multiapps.controller.web.configuration;
22

3+
import org.flowable.engine.HistoryService;
34
import org.flowable.engine.ProcessEngine;
5+
import org.flowable.engine.RuntimeService;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
68
import org.springframework.context.annotation.DependsOn;
7-
import org.springframework.context.annotation.Lazy;
89

10+
/**
11+
* Configuration for Flowable engine service beans.
12+
*
13+
* These beans are extracted from FlowableConfiguration to ensure proper initialization order.
14+
* The @DependsOn("processEngine") ensures that the ProcessEngineFactoryBean is fully initialized
15+
* and the ProcessEngine is available before these service beans are created.
16+
*
17+
* Note: @Lazy is not used here because:
18+
* 1. The ProcessEngine is properly managed via ProcessEngineFactoryBean, which handles lifecycle correctly
19+
* 2. Components like FlowableHistoricDataCleaner need HistoryService at startup for scheduled jobs
20+
* 3. Using @Lazy could cause unexpected initialization timing issues
21+
*/
922
@Configuration
1023
public class FlowableServicesConfiguration {
1124

12-
// Mark as @Lazy and @DependsOn to ensure 'processEngine' is produced first,
13-
// and service beans only resolve when actually needed.
14-
1525
@Bean
16-
@Lazy
1726
@DependsOn("processEngine")
18-
public org.flowable.engine.RuntimeService runtimeService(ProcessEngine processEngine) {
27+
public RuntimeService runtimeService(ProcessEngine processEngine) {
1928
return processEngine.getRuntimeService();
2029
}
2130

2231
@Bean
23-
@Lazy
2432
@DependsOn("processEngine")
25-
public org.flowable.engine.HistoryService historyService(ProcessEngine processEngine) {
33+
public HistoryService historyService(ProcessEngine processEngine) {
2634
return processEngine.getHistoryService();
2735
}
2836
}

0 commit comments

Comments
 (0)