SpringDaoSupport
@Component
public class SuperDAO extends HibernateDaoSupport { @Resource(name="sessionFactory")
public void setSuperSessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
} }
先上源代码:
@Component("logDAO")
public class LogDAOImpl extends SuperDAO implements LogDAO { public void save(Log log) { //this.getHibernateTemplate().save(log);
this.getHibernateTemplate().save(log);
//throw new RuntimeException("error!");
} }
<?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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com.bjsxt" /> <!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/spring" />
<property name="username" value="root" />
<property name="password" value="bjsxt" />
</bean>
--> <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean> <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="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--
<property name="annotatedClasses">
<list>
<value>com.bjsxt.model.User</value>
<value>com.bjsxt.model.Log</value>
</list>
</property>
-->
<property name="packagesToScan">
<list>
<value>com.bjsxt.model</value> </list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.bjsxt.service..*.*(..))" />
<aop:advisor pointcut-ref="bussinessService"
advice-ref="txAdvice" />
</aop:config> <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="getUser" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> </beans>
由于Super实现了HiberateSupportDao,又要为其注入hiberateTemplate 但直接注入会出问题,所以自定义了一个。在里面进行注入
setSuperSessionFactory
SpringDaoSupport的更多相关文章
随机推荐
- WIN7使用技巧 让电脑变身WiFi热点,让手机、笔记本共享上网,如何开启无线网络,共享无线网络
将win7电脑变身WIFI热点,让手机.笔记本共享上网 用win7建立无线局域网,可以共享上网可以局域网游戏. 开启windows 7的隐藏功能:虚拟WIFI和SoftAP(即虚拟无线AP),就可以让 ...
- 字段计算器VBS
ArcGIS属性表中右键可调用字段计算器.写一些简单代码可操作属性表,有VBS和Python两种. 现在要求是:如果"地块编码"为空,则将"地块编号"赋给&qu ...
- Office安装错误1402的解决
Office软件是我们工作是必备的,为了统一公司的办工软件,要把所有的WPS和Office2003版本全部换顾Office2010.在Win7下安装Office2010一般都不会存在什么大的问题,但遇 ...
- 算法笔记_212:第七届蓝桥杯软件类决赛真题(Java语言B组)
目录 1 愤怒小鸟 2 反幻方 3 打靶 4 路径之谜 5 碱基 6 圆圈舞 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 愤怒小鸟 愤怒小鸟 X星球愤怒的小鸟喜欢撞火车! 一根平直的铁轨上两火车 ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- CreateThread、_beginthreadex和AfxBeginThread .
创建线程好几个函数可以使用,可是它们有什么区别,适用于什么情况呢?参考了一些资料,写得都挺好的,这里做一些摘抄和整合. [参考1]CreateThread, AfxBeginThread,_begin ...
- 微信小程序-自定义底部导航
代码地址如下:http://www.demodashi.com/demo/14258.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- JavaScript实现碰撞检测(分离轴定理)
概述 分离轴定理是一项用于检测碰撞的算法.其适用范围较广,涵盖检测圆与多边形,多边形与多边形的碰撞:缺点在于无法检测凹多边形的碰撞.本demo使用Js进行算法实现,HTML5 canvas进行渲染. ...
- 执行存储过程报错——ora-01031:权限不足
1. 执行DDL报错 在oracle存储过程中,默认是可以直接执行DML和DQL的,但是执行CREATE这种的DDL则需要借助EXECUTE IMMEDIATE ···了,如下备份表语句 --抄表表备 ...
- mysql优化利器之explain
一.语法 {EXPLAIN | DESCRIBE | DESC} tbl_name [col_name | wild] {EXPLAIN | DESCRIBE | DESC} [explain_typ ...