Hibernate + Spring配置

Hibernate + Spring配置
<!-- 第一步:配置数据源 -->
<bean id="dateSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/oracle">
</property>
</bean>


<!-- 第一步:配置数据源 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/source.properties</value>
</list>
</property>
</bean>
<bean id="dateSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${source.driverClassName}" />
<property name="url" value="${source.url}" />
<property name="username" value="${source.username}" />
<property name="password" value="${source.password}" />
<property name="initialSize" value="4" />
<property name="maxActive" value="20" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testOnBorrow" value="true" />
</bean>



<!-- 第二步:配置sessionFactory -->
<!-- 配置大字段 -->
<bean id ="nativeJdbcExtractor" class ="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" lazy-init ="true" />
<bean id ="oracleLobHandler" class ="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init ="true" >
<property name ="nativeJdbcExtractor" ref ="nativeJdbcExtractor" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!-- ==============基础模块====================== -->
<!-- 单位BEAN -->
<value>com/nsoft/bean/BaseUnit.hbm.xml</value>
<!-- 部门BEAN -->
<value>com/nsoft/bean/BaseDept.hbm.xml</value>
</list>
<property>
<property name="lobHandler">
<ref local="oracleLobHandler"/>
</property>
</bean>

<!-- 第三步:配置事务管理器 -->
<bean name="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>


<!-- 第四步:配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="set*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="import*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--第五步:配置哪些类的哪些方法使用事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.nsoft.service.*.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>

<!-- 第六步:配置action对象 -->
<bean id="lwxtPublicDao" class="com.nsoft.dao.lwxtmanage.impl.LwxtPublicDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<bean id="lwxtPublicAction" class="com.nsoft.action.lwxtmanage.LwxtPublicAction" scope="prototype">
<property name="lwxtPublicService">
<ref bean="lwxtPublicService" />
</property>
</bean>
<bean id="lwxtPublicService" class="com.nsoft.service.lwxtmanage.impl.LwxtPublicServiceImpl">
<property name="lwxtTitleDao">
<ref bean="lwxtTitleDao" />
</property>
<property name="lwxtPublicDao">
<ref bean="lwxtPublicDao" />
</property>
<property name="baseSpecDao">
<ref bean="baseSpecDao" />
</property>
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值