Bug 1121764

Summary: Spring/JBPM: IllegalStateException: RuntimeManager with id spring-rmr is already active
Product: [Retired] JBoss BPMS Platform 6 Reporter: Josh West <jowest>
Component: jBPM CoreAssignee: Alessandro Lazarotti <alazarot>
Status: CLOSED EOL QA Contact: Ivo Bek <ibek>
Severity: high Docs Contact:
Priority: high    
Version: 6.0.2CC: ksuta
Target Milestone: DR2   
Target Release: 6.1.0   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-27 20:11:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
diff.txt none

Description Josh West 2014-07-21 19:51:04 UTC
Description of problem:

Multiple spring beans cannot depend on or autowire in the a KIE Runtime Manager through the `org.kie.spring.factorybeans.RuntimeManagerFactoryBean`. If multiple beans within a single spring application context depend on the runtime manager, a dependency exception is thrown with the following root cause, where `spring-rmr` is the identifier set in the runtime manager factory bean: 
'IllegalStateException: RuntimeManager with id spring-rmr is already active'

Version-Release number of selected component (if applicable):

BPMS 6.0.2GA

How reproducible:

100%

Steps to Reproduce:
1. Create spring two beans that inject runtimeManager
2. Start spring context

May be able to recreate the issue by calling context.getBean("runtimeManager") more than once in a single test also.

Sample test recreating issue:
https://github.com/shuawest/jboss-bpms-solutions/blob/master/sample-spring-app/src/test/java/com/redhat/solutions/bpms/JbpmSampleIntTest.java

Sample spring context: 
https://github.com/shuawest/jboss-bpms-solutions/blob/master/sample-spring-app/src/main/resources/jbpm-context.xml

Error occurs regardless of spring bean scope=singleton setting, or the runtime manager type.  


Additional info:
 Full example stack trace:

2014-07-21 15:44:49,906 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2942022d] to prepare test instance [com.redhat.solutions.bpms.JbpmSampleIntTest@7b8aeb1]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.redhat.solutions.bpms.JbpmSampleIntTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.kie.api.runtime.manager.RuntimeManager com.redhat.solutions.bpms.JbpmSampleIntTest.runtimeManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'runtimeManagerFactory': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RuntimeManager with id spring-rmr is already active
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:384)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.kie.api.runtime.manager.RuntimeManager com.redhat.solutions.bpms.JbpmSampleIntTest.runtimeManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'runtimeManagerFactory': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RuntimeManager with id spring-rmr is already active
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
	... 32 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'runtimeManagerFactory': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RuntimeManager with id spring-rmr is already active
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:151)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:110)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
	... 34 more
Caused by: java.lang.IllegalStateException: RuntimeManager with id spring-rmr is already active
	at org.jbpm.runtime.manager.impl.AbstractRuntimeManager.<init>(AbstractRuntimeManager.java:69)
	at org.jbpm.runtime.manager.impl.SingletonRuntimeManager.<init>(SingletonRuntimeManager.java:71)
	at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newSingletonRuntimeManager(RuntimeManagerFactoryImpl.java:69)
	at org.kie.spring.factorybeans.RuntimeManagerFactoryBean.getObject(RuntimeManagerFactoryBean.java:60)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144)
	... 42 more

Comment 2 Maciej Swiderski 2014-07-22 18:29:41 UTC
fix applied for both master and 6.1.x branch

droolsjbpm-integration
master:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/da1bec7ee52ef51877fca0879856905df15be3ce

droolsjbpm-integration
6.1.x:
https://github.com/droolsjbpm/droolsjbpm-integration/commit/bf29365c81ab8cce79f175f4d2ccb2e528e128ca

Comment 3 Ivo Bek 2014-09-08 14:50:02 UTC
Verified in BPMS 6.1.0.DR2

To verify this issue, I used the reproducer. However, it requires some changes to make it working with the current release.

First, I removed FixedRuntimeManagerFactoryBean and replaced it with org.kie.spring.factorybeans.RuntimeManagerFactoryBean to reproduce the problem. I should also mention that I used PostgreSQL instead of OracleDB. I successfully reproduced the problem and then I have done the changes that happened meanwhile, see the attached diff.txt file.

I just worry that some code will change in future and it will be necessary to update it again because for example JPATaskLifeCycleEventListener has changed and now it requires some boolean flag (called "flag") in the constructor that is not used and I have no idea what will be its purpose.

Comment 4 Ivo Bek 2014-09-08 14:50:50 UTC
Created attachment 935375 [details]
diff.txt

Comment 5 Maciej Swiderski 2014-09-08 17:58:58 UTC
(In reply to Ivo Bek from comment #3)
> Verified in BPMS 6.1.0.DR2
> 
> To verify this issue, I used the reproducer. However, it requires some
> changes to make it working with the current release.
> 
> First, I removed FixedRuntimeManagerFactoryBean and replaced it with
> org.kie.spring.factorybeans.RuntimeManagerFactoryBean to reproduce the
> problem. I should also mention that I used PostgreSQL instead of OracleDB. I
> successfully reproduced the problem and then I have done the changes that
> happened meanwhile, see the attached diff.txt file.
> 
> I just worry that some code will change in future and it will be necessary
> to update it again because for example JPATaskLifeCycleEventListener has
> changed and now it requires some boolean flag (called "flag") in the
> constructor that is not used and I have no idea what will be its purpose.
Ivo, this constructor was added to make it non CDI bean - no default constructor otherwise it would cause issues - meaning always be available for injections. As you noticed it does not do anything it's there just to prevent cdi of finding it.