转:成功整合spring+hibernate+jbpm的applicationContext配置

http://www.4ucode.com/Study/Topic/217963
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost:3306/test</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value/>
        </property>
    </bean>
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource"/>
        </property>
        <property name="mappingLocations">  
           <value>classpath*:/org/jbpm/**/*.hbm.xml</value>  
           </property>
        <property name="hibernateProperties">  
           <props>  
               <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
               <prop key="hibernate.hbm2ddl.auto">update</prop>
               <prop key="hibernate.jdbc.batch_size">0</prop>
           </props>
       </property> 
    </bean>
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>
    
    <!-- reading jBPM process definitions -->
    <bean id="websaleWorkflow1" class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
        <property name="definitionLocation"    value="processdefinition.xml"/>
    </bean>
    <!-- jBPM configuration--> 
    <bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
        <property name="sessionFactory" ref="sessionFactory"/>
        <property name="configuration" value="jbpm.cfg.xml"/>
        <property name="processDefinitions">
            <list>
                <ref local="websaleWorkflow1"/>
            </list>
        </property>
        <property name="createSchema" value="true"/>
    </bean>
    <!-- jBPM template -->
    <bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
        <constructor-arg index="0" ref="jbpmConfiguration"/>
        <constructor-arg index="1" ref="websaleWorkflow1"/>
    </bean>

</beans>




其中
<property name="mappingLocations">  
           <value>classpath*:/org/jbpm/**/*.hbm.xml</value>  
           </property>

很关键,spring是不会通过jbpm找到hibernate.cfg.xml 的,需要手工设置。


另外一个:使用多数据源的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
       default-autowire="byName" default-lazy-init="true">


    <context:annotation-config/>

    <context:component-scan base-package="org.jbpm.dao">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    </context:component-scan>

    <context:component-scan base-package="org.jbpm.service">
        <context:include-filter type="annotation"
                                expression="org.springframework.stereotype.Service"/>
    </context:component-scan>

    <!-- =================================================================== -->
    <!-- AOP: Configuration and Aspects                                      -->
    <!-- =================================================================== -->
    <aop:config>
        <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))" order="0"/>
    </aop:config>

    <tx:advice id="txAdvice">
        <tx:attributes>
            <!-- Read-only commented out to make things easier for end-users -->
            <!-- http://issues.appfuse.org/browse/APF-556 -->
            <!--tx:method name="get*" read-only="true"/-->
            <!--<tx:method name="save*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="update*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="remove*" propagation="REQUIRES_NEW"/>-->
            <!--<tx:method name="get*" read-only="true"/>-->
            <!--<tx:method name="list*" read-only="true"/>-->
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>

    <!-- Enable @Transactional support -->
    <!--<tx:annotation-driven/>-->

    <!-- Enable @AspectJ support -->
    <aop:aspectj-autoproxy/>

    <!-- Enable @Configured support -->
    <!--<aop:spring-configured/>-->

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean>

    <bean id="basicdataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>


    <bean id="xadataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
          init-method="init" destroy-method="close">
        <property name="className" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
        <property name="uniqueName" value="jdbc/testDS1" />
        <property name="minPoolSize" value="1" />
        <property name="maxPoolSize" value="5" />
        <property name="allowLocalTransactions" value="true" />
        <property name="driverProperties">
            <props>
                <prop key="URL">${jdbc.url}</prop>
                <prop key="user">${jdbc.username}</prop>
                <prop key="password">${jdbc.password}</prop>
            </props>
        </property>
    </bean>


    <bean id="txManager"
          class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="bitronixTransactionManager" />
        <property name="userTransaction" ref="bitronixTransactionManager" />
    </bean>

    <bean id="bitronixTransactionManager" factory-method="getTransactionManager"
          class="bitronix.tm.TransactionManagerServices" depends-on="xadataSource,txManager"
          destroy-method="shutdown" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="basicdataSource"/>
        <property name="persistenceUnitName" value="leaveJPA"/>
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>

    <bean id="entityManagerFactoryJbpmPersistanceJpa" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="xadataSource" />
        <property name="persistenceUnitName" value="org.jbpm.persistence.jpa" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>

    <bean id="entityManagerFactoryJbpmTask"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="basicdataSource" />
        <property name="persistenceUnitName" value="org.jbpm.task" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                <property name="showSql" value="true" />

                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryJbpmPersistanceJpa"/>
    </bean>

    <bean id="taskTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryJbpmTask"/>
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>


    <!--<bean id="md5PasswordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>-->

</beans>

你可能感兴趣的:(转:成功整合spring+hibernate+jbpm的applicationContext配置)