Mule+Spring+jbpm

法一:完全在spring.xml里面配置mule的所有内容

该方法的缺点的是配置umo比mule语法更加繁琐

法二:两个配置分件都用,不过mule里面需要加入一些mule-spring的标记
其本质是将mule.xml转换成法一中的spring.xml

该方法比较适合在现有的spring应用中,加入mule

法三:在mule server的container内启动spring,各自用自己的配置文件格式,适用于以mule server为主,spring为辅的应用

假设有两个bean,restaurantWaiter和kitchenService,前者作为UMO来接收消息,然后调用service
1 spring-context.xml
<beans>
<bean id='restaurantWaiter' singleton='false' class='com.foo.RestaurantWaiter'>
<property name='kitchenService'><ref local='kitchenService'/></property>
</bean>
<bean id='kitchenService' class='com.foo.KitchenService'/>
</beans>

2 mule.xml
<mule-descriptor name="Restaurant Waiter"
inboundEndpoint="vm://order.queue"
implementation="restaurantWaiter">
</mule-descriptor>

为了让Mule能够识别restaurantWaiter,需要配置
<mule-configuration>
....
<container-context className='org.mule.extras.spring.SpringContainerContext'>
<properties>
<property name='configFile' value='../conf/applicationContext.xml'/>
</properties>
</container-context>
....
</mule-configuration>

Spring+jbpm+mule 三者是可以完美结合的

<!-- JBPM Datasource -->
<bean id="jbpmDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<spring-property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></spring-property>
<spring-property name="url"><value>jdbc:hsqldb:mem:.;sql.enforce_strict_size=true</value></spring-property>
<spring-property name="username"><value>sa</value></spring-property>
<spring-property name="password"><value></value></spring-property>
</bean>

<!-- JBPM Hibernate SessionFactory -->
<bean id="jbpmSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<spring-property name="dataSource">
<ref local="jbpmDataSource" />
</spring-property>
<spring-property name="mappingLocations">
<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
</spring-property>
<spring-property name="typeDefinitions">
<ref local="jbpmTypes" />
</spring-property>
<spring-property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">3</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<!-- Create/update the database tables automatically when the JVM starts up -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</spring-property>
</bean>

<!-- JBPM data types -->
<bean id="jbpmTypes" class="org.springframework.orm.hibernate3.TypeDefinitionBean">
<spring-property name="typeName"><value>string_max</value></spring-property>
<spring-property name="typeClass"><value>org.jbpm.db.hibernate.StringMax</value></spring-property>
</bean>

<!-- jBPM Configuration -->
<bean id="jbpmConfig" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBeanWorkaround">
<spring-property name="sessionFactory">
<ref local="jbpmSessionFactory"/>
</spring-property>
<spring-property name="configuration">
<value>jbpm.cfg.xml</value>
</spring-property>
<spring-property name="processDefinitions">
<spring-list>
<bean id="loanBroker" class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
<spring-property name="definitionLocation">
<value>loan-broker-process.xml</value>
</spring-property>
</bean>
</spring-list>
</spring-property>
<spring-property name="createSchema"><value>false</value></spring-property>
</bean>

上面的部分已经足够将spring和jbpm结合起来了,appfuse中的集合也就做到上面的步骤
该集成使用了spring-modules-jbpm31.jar
具体使用的演示
JbpmConfiguration config = (JbpmConfiguration) applicationContext.getBean("jbpmConfig");
JbpmContext context = config.createJbpmContext();
ProcessDefinition definition = context.getGraphSession().findLatestProcessDefinition("testProcess");

//下面是mule中使用jbpm的配置,使用org.jbpm.msg.mule.Jbpm对其进行了封装,以便在jBpmConnector中使用

<!-- ***************************************************
BPMS Configuration
*************************************************** -->
<!-- BPMS object for Mule's BPM Connector -->
<bean id="jbpm" class="org.jbpm.msg.mule.Jbpm" destroy-method="destroy">
<spring-property name="jbpmConfiguration">
<ref local="jbpmConfig" />
</spring-property>
</bean>


mule.xml

<connector name="jBpmConnector" className="org.mule.providers.bpm.ProcessConnector">
<properties>
<!-- This field in LoanQuoteRequest holds the unique process ID. -->
<property name="processIdField" value="requestId" />
<!-- jBpm itself is configured by a series of Spring beans at the end of
this file. -->
<spring-property name="bpms"><ref local="jbpm" /></spring-property>
</properties>
</connector>

mule in spring-context

muleContext.xml

<bean id="muleManager" class="org.mule.config.spring.config.UMOManagerFactoryBean">
<property name="configuration"><ref local="muleConfiguration"/></property>
<property name="messageEndpoints"><ref local="messageEndpoints"/></property>
<property name="connectors"><ref local="connectorList"/></property>
<property name="transformers"><ref local="transformerList"/></property>
<property name="endpoints">
<list>
<ref local="globalInboundJmsEndpoint"/>
<ref local="globalOutboundJmsEndpoint"/>
<ref local="globalHttpEndpoint"/>
</list>
</property>
<property name="interceptorStacks"><ref local="interceptorsMap"/></property>
<property name="model"><ref local="model"/></property>
</bean>

or 一种简单一些的配置

muleContext.xml

<bean id="muleManager" class="org.mule.extras.spring.config.AutowireUMOManagerFactoryBean" destroy-method="dispose" singleton="true"/>
<!-- Used to set mule object names to their corresponding bean id -->
<bean id="muleNameProcessor" class="org.mule.extras.spring.config.MuleObjectNameProcessor"/>
<!-- The mule client we will use to send events to the mule server -->
<bean id="muleClient" class="org.mule.extras.client.MuleClient" depends-on="muleManager"/>

web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mule-spring-config.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

这样spring启动的时候,mule server也就启动了


========
使用spring和mule混合标签的config.xml

SpringConfigurationBuilder builder = new SpringConfigurationBuilder();
UMOManager manager = builder.configure("mule-spring-config.xml,mule-spring-components.xml");

接下来不需要做任何处理,因为之后都会通过
MuleManager.getInstance() 来获得该manager

<!DOCTYPE mule-configuration PUBLIC "-//SymphonySoft //DTD mule-configuration XML V1.0//EN"
"http://www.symphonysoft.com/dtds/mule/mule-spring-configuration.dtd">

//create a client
MuleClient client = new MuleClient();
//send a jms message asynchronously
client.dispatch("jms://my.queue", "some data", null);
//or to receive a pop3 message via a configured mailbox
UMOMessage message = client.receive("pop3://myInboxProvider", 3000);
//or synchonous send a inter-vm message
UMOMessage message2 = client.send("vm://my.object", "Some more data", null);

你可能感兴趣的:(spring,bean,xml,Hibernate,jbpm)