读书人

spring与hibernate集成:全部bean共享

发布时间: 2012-06-29 15:48:46 作者: rapoo

spring与hibernate集成:所有bean共享一个代理基类(applicationContext.xml文件)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!--在spring中加入外部*.properties文件-->
<bean id="placeholderConfig"
dependency-check="none">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="user">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${c3p0.maxPoolSize}</value>
</property>
<property name="maxIdleTime">
<value>${c3p0.maxIdleTime}</value>
</property>
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}</value>
</property>
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
<property name="numHelperThreads">
<value>${c3p0.numHelperThreads}</value>
</property>
</bean>


<!--配置sessionFactory,一个sessionFactory对应一个数据库-->
<bean id="mySessionFactory"
/>
</property>
<!--关联hibernate映射文件-->
<property name="mappingDirectoryLocations">
<list>
<value>
<!--目录com/lisco/pub/domain/hibernate下的所有hibernate映射文件-->
classpath*:/com/lisco/pub/domain/hibernate
</value>
<value>
classpath*:/com/lisco/ypgl/domain/hibernate
</value>
</list>
</property>
<!--配置hibernate.cfg.xml中的属性,这样就可以不用hibernate.cfg.xml文件了-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<!--配置是否加载配置文件时自动生成表结构-->
<prop key="hibernate.hbm2ddl.auto">
update
</prop>

<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.jdbc.fetch_size">
${hibernate.jdbc.fetch_size}
</prop>
<prop key="hibernate.jdbc.batch_size">
${hibernate.jdbc.batch_size}
</prop>
<prop key="hibernate.connection.release_mode">
${hibernate.connection.release_mode}
</prop>
<prop key='hibernate.query.factory_class'>
${hibernate.query.factory_class}
</prop>
</props>
</property>
</bean>


<!--配置事务管理器-->
<bean id="myTransactionManager"
/>
</property>
</bean>


<!--配置事务代理,所有Bean共享一个代理基类-->
<bean id="myTransactionProxyFactoryBean" lazy-init="true"
/>
</property>
<!--配置事务的传播特性-->
<property name="transactionAttributes">
<props>
<!--所有以create、update、delete、save开头的方法采用PROPAGATION_REQUIRED的事务策略-->
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<!--其他的方法采用PROPAGATION_REQUIRED而且readOnly的事务策略-->
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>


<!--注册service类-->
<bean id="aqgl_PunishRecService"
/>
</property>
</bean>
<bean id="aqgl_RectificationRecService"
/>
</property>
</bean>


<!-- 注册service类的代理,parent属性指明代理类的父类为上面配置的事务代理 -->
<bean id="aqgl_PunishRecService_proxy"
parent="myTransactionProxyFactoryBean">
<!--配置此代理的目标对象-->
<property name="target">
<ref local="aqgl_PunishRecService" />
</property>
</bean>
<bean id="aqgl_RectificationRecService_proxy"
parent="myTransactionProxyFactoryBean">
<property name="target">
<ref local="aqgl_RectificationRecService" />
</property>
</bean>





<!--为beanNames属性标注的beans配置拦截器,拦截器由interceptorNames属性定义,value值为-->
<bean name="loggingAutoProxy"
/>
<import resource="com/lisco/ypgl/config/applicationContext-ypgl.xml" />
<import resource="com/lisco/pub/config/applicationContext-pub.xml" />
<import resource="com/lisco/xmsz/config/applicationContext-xmsz.xml" />
<import resource="com/lisco/excelprint/config/applicationContext-excelprint.xml" />
<import resource="com/lisco/aqgl/config/applicationContext-aqgl.xml" />
<import resource="com/lisco/bzypgl/config/applicationContext-bzypgl.xml" />
<import resource="com/lisco/clsb/config/applicationContext-clsb.xml" />
<import resource="com/lisco/kcgl/config/applicationContext-kcgl.xml" />
<import resource="com/lisco/lygl/config/applicationContext-lygl.xml" />
<import resource="com/lisco/rcjl/config/applicationContext-rcjl.xml" />
<import esource="com/lisco/rygl/config/applicationContext-rygl.xml" />
<import resource="com/lisco/sbgl/config/applicationContext-sbgl.xml" />
<import resource="com/lisco/sysrkgl/config/applicationContext-sysrkgl.xml" />
<import resource="com/lisco/dictionary/config/applicationContext_dictionary.xml" />
</beans>

读书人网 >XML SOAP

热点推荐