Error creating bean with name 'processEngineFactoryBean'

Hi, everyone! I tried to use Transaction in my project so I followed insctruction from Spring Transaction Integration | docs.camunda.org
but I use Configuration.java class instead of application.xml so my Java class is:

import org.camunda.bpm.engine.rest.security.auth.ProcessEngineAuthenticationFilter;
import org.camunda.bpm.engine.spring.ProcessEngineFactoryBean;
import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;


@Configuration
public class ProjectConfiguration {
    @Autowired
    protected DataSource dataSource;
    
    @Bean
    public FilterRegistrationBean<ProcessEngineAuthenticationFilter> authenticationFilter() {
        FilterRegistrationBean<ProcessEngineAuthenticationFilter> registration =
                new FilterRegistrationBean<>();
        ProcessEngineAuthenticationFilter myFilter = new ProcessEngineAuthenticationFilter();
        registration.setFilter(myFilter);
        registration.addUrlPatterns("/rest/*");
        registration.addInitParameter("authentication-provider",
                "org.camunda.bpm.engine.rest.security.auth.impl.HttpBasicAuthenticationProvider");
        registration.setName("camunda-auth");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public AuthorizationConfiguration getAuthorizationConfiguration() {
        return new AuthorizationConfiguration();
    }

    @Bean
    public DataSourceTransactionManager transactionManager(){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(dataSource);
        return dataSourceTransactionManager;
    }


    @Bean
    public SpringProcessEngineConfiguration myProcessEngineConfiguration(){
        SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
        processEngineConfiguration.setTransactionManager(transactionManager());
        processEngineConfiguration.setDataSource(dataSource);
        processEngineConfiguration.setDatabaseSchemaUpdate("true");
        processEngineConfiguration.setJobExecutorActivate(false);
        processEngineConfiguration.setHistory("full");
        return processEngineConfiguration;
    }

    @Primary
    @Bean
    public ProcessEngineFactoryBean processEngine(){
        ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
        processEngineFactoryBean.setProcessEngineConfiguration(myProcessEngineConfiguration());
        return processEngineFactoryBean;
    }
    
}

My main class is:

import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableProcessApplication
@EnableTransactionManagement
public class Application implements CommandLineRunner {

public static void main(String args) {
SpringApplication.run(Application.class);
}

@Override
public void run(String… args) throws Exception {

}
}

Unfortunately, get this exception:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‚Äėorg.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration‚Äô: Unsatisfied dependency expressed through field ‚ÄėprocessEngine‚Äô; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‚ÄėprocessEngineFactoryBean‚Äô: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Task already scheduled or cancelled
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at ru.sec2.Application.main(Application.java:16) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‚ÄėprocessEngineFactoryBean‚Äô: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Task already scheduled or cancelled
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1818) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1266) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1510) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1467) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1250) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
… 19 common frames omitted
Caused by: java.lang.IllegalStateException: Task already scheduled or cancelled
at java.base/java.util.Timer.sched(Timer.java:402) ~[na:na]
at java.base/java.util.Timer.scheduleAtFixedRate(Timer.java:329) ~[na:na]
at org.camunda.bpm.engine.impl.metrics.reporter.DbMetricsReporter.start(DbMetricsReporter.java:59) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.ProcessEngineImpl.(ProcessEngineImpl.java:139) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:871) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.spring.SpringTransactionsProcessEngineConfiguration.buildProcessEngine(SpringTransactionsProcessEngineConfiguration.java:63) ~[camunda-engine-spring-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:55) ~[camunda-engine-spring-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:34) ~[camunda-engine-spring-7.13.0.jar:7.13.0]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
… 30 common frames omitted

My project powered by Spring 2.2.5. and CamundaEngine 7.13
I saw a similar topic on the forum but advises from that topic didn’t work for me. I would be happy to get any idea.
Thanks in advance!

I solve this problem! First of all, I exclude the default bean like this:

@SpringBootApplication(exclude = {CamundaBpmAutoConfiguration.class})
@EnableProcessApplication
@EnableTransactionManagement
public class Application implements CommandLineRunner {

  public static void main(String[] args) {
    SpringApplication.run(Application.class);
  }

  @Override
  public void run(String... args) throws Exception {

  }
}

and then create my own configuration file like this:

@EnableConfigurationProperties({
        CamundaBpmProperties.class,
        ManagementProperties.class
})
@Import({
        CamundaBpmConfiguration.class,
        CamundaBpmActuatorConfiguration.class,
        CamundaBpmPluginConfiguration.class,
        SpringProcessEngineServicesConfiguration.class
})
@ConditionalOnProperty(prefix = CamundaBpmProperties.PREFIX, name = "enabled", matchIfMissing = true)
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
@Configuration
public class ProjectConfiguration {
    @Autowired
    protected DataSource dataSource;
    @Autowired
    protected ProcessEngineConfigurationImpl processEngineConfigurationImpl;
    @Autowired
    protected SpringTransactionsProcessEngineConfiguration springTransactionsProcessEngineConfiguration;
    @Autowired
    protected SpringProcessEngineConfiguration processEngineConfiguration;


    @Bean
    public FilterRegistrationBean<ProcessEngineAuthenticationFilterauthenticationFilter() {
        FilterRegistrationBean<ProcessEngineAuthenticationFilterregistration =
                new FilterRegistrationBean<>();
        ProcessEngineAuthenticationFilter myFilter = new ProcessEngineAuthenticationFilter();
        registration.setFilter(myFilter);
        registration.addUrlPatterns("/rest/*");
        registration.addInitParameter("authentication-provider",
                "org.camunda.bpm.engine.rest.security.auth.impl.HttpBasicAuthenticationProvider");
        registration.setName("camunda-auth");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public AuthorizationConfiguration getAuthorizationConfiguration() {
        return new AuthorizationConfiguration();
    }

    @Bean
    public DataSourceTransactionManager transactionManager(){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(dataSource);
        return dataSourceTransactionManager;
    }


    @Bean
    public SpringProcessEngineConfiguration myProcessEngineConfiguration(){
        processEngineConfiguration.setTransactionManager(transactionManager());
        processEngineConfiguration.setJpaHandleTransaction(true);
        processEngineConfiguration.setDataSource(dataSource);
        processEngineConfiguration.setDatabaseSchemaUpdate("true");
        processEngineConfiguration.setJobExecutorActivate(false);
        processEngineConfiguration.setHistory("full");
        processEngineConfiguration.setJavaSerializationFormatEnabled(true);
        return processEngineConfiguration;
    }


    @Bean
    public ProcessEngineFactoryBean myProcessEngine(){
        ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
        processEngineFactoryBean.setProcessEngineConfiguration(myProcessEngineConfiguration());
        return processEngineFactoryBean;
    }


    @Bean
    @Primary
    public CommandExecutor commandExecutorTxRequired() {
        return myProcessEngineConfiguration().getCommandExecutorTxRequired();
    }

    @Bean
    public CommandExecutor commandExecutorTxRequiresNew() {
        return myProcessEngineConfiguration().getCommandExecutorTxRequiresNew();
    }

    @Bean
    public CommandExecutor commandExecutorSchemaOperations() {
        return myProcessEngineConfiguration().getCommandExecutorSchemaOperations();
    }


    @Bean
    public CamundaBpmVersion camundaBpmVersion() {
        return new CamundaBpmVersion();
    }

    @Bean
    public ProcessApplicationEventPublisher processApplicationEventPublisher(ApplicationEventPublisher publisher) {
        return new ProcessApplicationEventPublisher(publisher);
    }
}

about @Autowired I know that it looked weird because those classes are extended to each other but they are abstract and have a lot of established property and I needed only set transactionalManager and create a SpringProcessEngineConfigurationBean so in my case it looked like a desicion.

2 Likes

Hi @Marat
Thanks for posting the solution you found - i’ve edited your post slightly to make the format easier to read. :slight_smile:

1 Like

Hi! Thank you for your help. Unfortunately, I simplified the solution and would like to share it. I will try to use your advice about the text.

I simplified the solution and keen to stress that I use JpaTransactionManager because I need it but you can use others transactionMagaer instead.

@EnableAutoConfiguration
@EnableJpaRepositories
@SpringBootApplication(scanBasePackages = {‚Äúru.sec2‚ÄĚ})
@EnableProcessApplication
@EnableTransactionManagement
public class Application implements CommandLineRunner {

public static void main(String args) {
SpringApplication.run(Application.class);
}

@Override
public void run(String… args) throws Exception {

}
}

And here is my configuration file with imports:

import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.rest.security.auth.ProcessEngineAuthenticationFilter;
import org.camunda.bpm.engine.spring.ProcessEngineFactoryBean;
import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;
import org.camunda.bpm.spring.boot.starter.CamundaBpmAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
@Import({
CamundaBpmAutoConfiguration.class
})
@AutoConfigureAfter(CamundaBpmAutoConfiguration.class)
@Configuration
public class ProjectConfiguration {
@Autowired
protected DataSource dataSource;
@Autowired
protected ProcessEngineFactoryBean processEngineFactoryBean;

@Bean
public FilterRegistrationBean<ProcessEngineAuthenticationFilter> authenticationFilter() {
    FilterRegistrationBean<ProcessEngineAuthenticationFilter> registration =
            new FilterRegistrationBean<>();
    ProcessEngineAuthenticationFilter myFilter = new ProcessEngineAuthenticationFilter();
    registration.setFilter(myFilter);
    registration.addUrlPatterns("/rest/*");
    registration.addInitParameter("authentication-provider",
            "org.camunda.bpm.engine.rest.security.auth.impl.HttpBasicAuthenticationProvider");
    registration.setName("camunda-auth");
    registration.setOrder(1);
    return registration;
}

@Bean
public AuthorizationConfiguration getAuthorizationConfiguration() {
    return new AuthorizationConfiguration();
}

@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(){
    JpaTransactionManager dataSourceTransactionManager = new JpaTransactionManager();
    dataSourceTransactionManager.setDataSource(dataSource);
    return dataSourceTransactionManager;
}

@Bean
public SpringProcessEngineConfiguration myProcessEngineConfiguration(){
    SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
    processEngineConfiguration.setTransactionManager(transactionManager());
    processEngineConfiguration.setDataSource(dataSource);
    processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    processEngineConfiguration.setJobExecutorActivate(false);
    processEngineConfiguration.setHistory("full");
    processEngineConfiguration.setJpaHandleTransaction(true);
    processEngineConfiguration.setJpaCloseEntityManager(true);
    processEngineFactoryBean.setProcessEngineConfiguration(processEngineConfiguration);
    return processEngineConfiguration;
}

}