CdiJtaProcessEngineConfiguration 在加载之前请求事务管理器
CdiJtaProcessEngineConfiguration requests Transaction Manager before its is loaded
我成功地让 Activiti 使用 JtaProcessEngineConfiguration 并单独使用 CdiStandaloneProcessEngineConfiguration。
但是我无法让 CdiJtaProcessEngineConfiguration 工作,我的配置示例如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">
" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans.xsd">
</a> <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/TransactionManager"></property>
<property name="resourceRef" value="true" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionsExternallyManaged" value="true" />
<property name="dataSourceJndiName" value="openejb:Resource/jdbc/AppDS" />
<property name="databaseSchemaUpdate" value="false"/>
<property name="jobExecutorActivate" value="false"/>
<property name="asyncExecutorEnabled" value="true"/>
<property name="asyncExecutorActivate" value="true"/>
<property name="history" value="audit"/>
</bean>
</beans>
错误是
javax.naming.NameNotFoundException: Name [TransactionManager] is not
bound in this Context. Unable to find [TransactionManager].
堆栈跟踪如下
2016-11-29 13:47:37 ERROR ProcessEngines:174 - Exception while initializing process engine: Error creating bean with name 'processEngineConfiguration' defined in resource loaded through InputStream: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in resource loaded through InputStream: Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngineConfiguration' defined in resource loaded through InputStream: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in resource loaded through InputStream: Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary
我不确定接下来要尝试什么
我使用的应用服务器是Tomee-plus 1.7.3
干杯
亚当
[编辑 1] 请注意,您需要在应用准备就绪时加载 JtaProcessEngineConfiguration 手册,但 CdiStandaloneProcessEngineConfiguration 和 CdiJtaProcessEngineConfiguration 会通过 ActivitiExtension class.
自动加载
[编辑 2]
在扩展的 JtaProcessEngineConfiguration(无 cdi)中按如下方式查找事务管理器时(根据@Romain Manni-Bucau 建议)
try {
InitialContext initialContext = new InitialContext();
try {
transactionManager = (TransactionManager) initialContext.lookup("openejb:Resource/TransactionManager");
} finally {
initialContext.close();
}
} catch (NamingException e) {
LOGGER.error(e.getMessage(), e);
}
我得到以下异常跟踪
2016-12-06 09:16:35 ERROR TestJtaProcessEngineConfiguration:29 - Name "Resource/TransactionManager" not found.
javax.naming.NameNotFoundException: Name "Resource/TransactionManager" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:119)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
<snip>
[编辑 3] 尝试使用 "java.naming.factory.initial=org.apache.openejb.core.OpenEJBInitialContextFactory" 导致以下堆栈跟踪。
Cannot instantiate class: org.apache.openejb.core.OpenEJBInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.openejb.core.OpenEJBInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
但是使用 "openejb:TransactionManager" 的 jndi 字符串是可行的
成功
工作配置使用 jndiName 属性 如下。
<property name="jndiName" value="openejb:TransactionManager"></property>
使用 openejb 怎么样:Resource/TransactionManager 容器一启动就可用(甚至在任何部署之前)?这将使依赖于事务管理器的任何代码不依赖于启动生命周期。
在@Romain Manni-Bucau 的帮助下,解决方案是 "openejb:TransactionManager"
的 jndi 名称
我允许我接受@Romain Manni-Bucau 回答的编辑被拒绝,在这里发布正确答案。
我成功地让 Activiti 使用 JtaProcessEngineConfiguration 并单独使用 CdiStandaloneProcessEngineConfiguration。
但是我无法让 CdiJtaProcessEngineConfiguration 工作,我的配置示例如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">
" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans.xsd">
</a> <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/TransactionManager"></property>
<property name="resourceRef" value="true" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionsExternallyManaged" value="true" />
<property name="dataSourceJndiName" value="openejb:Resource/jdbc/AppDS" />
<property name="databaseSchemaUpdate" value="false"/>
<property name="jobExecutorActivate" value="false"/>
<property name="asyncExecutorEnabled" value="true"/>
<property name="asyncExecutorActivate" value="true"/>
<property name="history" value="audit"/>
</bean>
</beans>
错误是
javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].
堆栈跟踪如下
2016-11-29 13:47:37 ERROR ProcessEngines:174 - Exception while initializing process engine: Error creating bean with name 'processEngineConfiguration' defined in resource loaded through InputStream: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in resource loaded through InputStream: Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngineConfiguration' defined in resource loaded through InputStream: Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in resource loaded through InputStream: Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary
我不确定接下来要尝试什么
我使用的应用服务器是Tomee-plus 1.7.3
干杯 亚当
[编辑 1] 请注意,您需要在应用准备就绪时加载 JtaProcessEngineConfiguration 手册,但 CdiStandaloneProcessEngineConfiguration 和 CdiJtaProcessEngineConfiguration 会通过 ActivitiExtension class.
自动加载[编辑 2] 在扩展的 JtaProcessEngineConfiguration(无 cdi)中按如下方式查找事务管理器时(根据@Romain Manni-Bucau 建议)
try {
InitialContext initialContext = new InitialContext();
try {
transactionManager = (TransactionManager) initialContext.lookup("openejb:Resource/TransactionManager");
} finally {
initialContext.close();
}
} catch (NamingException e) {
LOGGER.error(e.getMessage(), e);
}
我得到以下异常跟踪
2016-12-06 09:16:35 ERROR TestJtaProcessEngineConfiguration:29 - Name "Resource/TransactionManager" not found.
javax.naming.NameNotFoundException: Name "Resource/TransactionManager" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:119)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
<snip>
[编辑 3] 尝试使用 "java.naming.factory.initial=org.apache.openejb.core.OpenEJBInitialContextFactory" 导致以下堆栈跟踪。
Cannot instantiate class: org.apache.openejb.core.OpenEJBInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.openejb.core.OpenEJBInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
但是使用 "openejb:TransactionManager" 的 jndi 字符串是可行的
成功 工作配置使用 jndiName 属性 如下。
<property name="jndiName" value="openejb:TransactionManager"></property>
使用 openejb 怎么样:Resource/TransactionManager 容器一启动就可用(甚至在任何部署之前)?这将使依赖于事务管理器的任何代码不依赖于启动生命周期。
在@Romain Manni-Bucau 的帮助下,解决方案是 "openejb:TransactionManager"
的 jndi 名称我允许我接受@Romain Manni-Bucau 回答的编辑被拒绝,在这里发布正确答案。