Author: rebody
Date: 2010-05-28 02:09:45 -0400 (Fri, 28 May 2010)
New Revision: 6380
Added:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java
Log:
JBPM-2710 solve Circular Reference error for spring integration
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java 2010-05-28
06:01:59 UTC (rev 6379)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java 2010-05-28
06:09:45 UTC (rev 6380)
@@ -36,23 +36,23 @@
/**
* this environment factory will see only the singleton beans.
- *
+ *
* The created {@link SpringEnvironment}s will see the prototype beans and it
* will cache them.
- *
+ *
* @author Andries Inze
*/
public class SpringProcessEngine extends ProcessEngineImpl implements EnvironmentFactory,
ProcessEngine {
private static final Log log = Log.getLog(SpringProcessEngine.class.getName());
-
+
private static final long serialVersionUID = 1L;
private ApplicationContext applicationContext;
public static ProcessEngine create(ConfigurationImpl configuration) {
SpringProcessEngine springProcessEngine = null;
-
+
ApplicationContext applicationContext = null;
if (configuration.isInstantiatedFromSpring()) {
applicationContext = (ApplicationContext) configuration.getApplicationContext();
@@ -66,7 +66,7 @@
springProcessEngine.processEngineWireContext
.getWireDefinition()
.addDescriptor(new ProvidedObjectDescriptor(hibernateConfiguration, true));
-
+
springProcessEngine.checkDb(configuration);
} else {
@@ -77,7 +77,7 @@
applicationContext = new ClassPathXmlApplicationContext(springCfg);
springProcessEngine = (SpringProcessEngine)
applicationContext.getBean("processEngine");
}
-
+
return springProcessEngine;
}
@@ -99,18 +99,24 @@
@SuppressWarnings("unchecked")
@Override
public <T> T get(Class<T> type) {
+ T candidateComponent = super.get(type);
+
+ if (candidateComponent != null) {
+ return candidateComponent;
+ }
+
String[] names = applicationContext.getBeanNamesForType(type);
-
+
if (names.length >= 1) {
-
+
if (names.length > 1 && log.isWarnEnabled()) {
log.warn("Multiple beans for type " + type + " found. Returning
the first result.");
}
-
+
return (T) applicationContext.getBean(names[0]);
}
- return super.get(type);
+ return null;
}
@Override
Added:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java
===================================================================
---
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java
(rev 0)
+++
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java 2010-05-28
06:09:45 UTC (rev 6380)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.test.spring.circularreference;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.AbstractTransactionalSpringJbpmTestCase;
+
+public class CircularReferenceTest extends AbstractTransactionalSpringJbpmTestCase {
+ public void testGetRepositoryService() {
+ assertNotNull(repositoryService);
+ }
+}
Added:
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml
===================================================================
---
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml
(rev 0)
+++
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml 2010-05-28
06:09:45 UTC (rev 6380)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans
xmlns="http://www.springframework.org/schema/beans"
+
xmlns:aop="http://www.springframework.org/schema/aop"
+
xmlns:context="http://www.springframework.org/schema/context"
+
xmlns:tx="http://www.springframework.org/schema/tx"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
+
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.0.xsd
+
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
+
+ <bean id="springHelper"
class="org.jbpm.pvm.internal.processengine.SpringHelper">
+ <property name="jbpmCfg"
value="org/jbpm/test/spring/circularreference/jbpm.cfg.xml" />
+ </bean>
+
+ <bean id="processEngine" factory-bean="springHelper"
factory-method="createProcessEngine" />
+
+ <bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
+
+ <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="configLocation"
value="classpath:org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml"
/>
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"
/>
+ <property name="url" value="jdbc:hsqldb:." />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </bean>
+</beans>
Added:
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml
===================================================================
---
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml
(rev 0)
+++
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml 2010-05-28
06:09:45 UTC (rev 6380)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <import resource="jbpm.default.cfg.xml" />
+ <import resource="jbpm.jpdl.cfg.xml" />
+ <import resource="jbpm.bpmn.cfg.xml" />
+ <import resource="jbpm.identity.cfg.xml" />
+ <import resource="jbpm.businesscalendar.cfg.xml" />
+ <import resource="jbpm.console.cfg.xml" />
+
+ <!-- Spring configuration -->
+ <import resource="jbpm.tx.spring.cfg.xml" />
+
+</jbpm-configuration>
Added:
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml
===================================================================
---
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml
(rev 0)
+++
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml 2010-05-28
06:09:45 UTC (rev 6380)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+
+ <property
name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+ <property name="hibernate.format_sql">true</property>
+
+ <property
name="hibernate.hbm2ddl.auto">create-drop</property>
+
+ <mapping resource="jbpm.repository.hbm.xml" />
+ <mapping resource="jbpm.execution.hbm.xml" />
+ <mapping resource="jbpm.history.hbm.xml" />
+ <mapping resource="jbpm.task.hbm.xml" />
+ <mapping resource="jbpm.identity.hbm.xml" />
+
+ </session-factory>
+</hibernate-configuration>
Added:
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties
===================================================================
---
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties
(rev 0)
+++
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties 2010-05-28
06:09:45 UTC (rev 6380)
@@ -0,0 +1,4 @@
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+log4j.rootLogger=info, stdout