<property name="locations"> <value>classpath:jdbc.properties</value> </property>
<bean id="dataSource" destroy-method="close" 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="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="personDao" class="cn.qjc.hibernate.dao.impl.PersonDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory2"/>
</property>
</bean>
<bean id="personService" class="cn.qjc.hibernate.service.impl.PersonServiceImpl">
<property name="personDao">
<ref bean="personDao"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory2"/>
</property>
</bean>
<tx:advice transaction-manager="transactionManager" id="tx">
<tx:attributes>
<!--
name 目标方法的范围
islation 隔离级别
propagation 传播属性
read-only
true 只读事务
false 读写事务
-->
<tx:method name="save*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* cn.qjc.hibernate.service.impl.*.*(..))" id="perform"/>
<span style="white-space:pre"> </span><!-- 将切入点应用到增强方法 -->
<aop:advisor advice-ref="tx" pointcut-ref="perform"/>
</aop:config>
* 实现方法一:继承HibernateDaoSupport
* @author qjc
*/
public class PersonDaoImpl extends HibernateDaoSupport implements PersonDao{
@Override
public void savePerson(Person person) {
this.getHibernateTemplate().save(person);
}
}
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory2"></property>
</bean>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<!-- singleSession默认为true,若设置为false则等于没有OpenSessionInView -->
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/PersonService</url-pattern>
</filter-mapping>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有