@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的更多相关文章

随机推荐

  1. Android MVP 构架封装

    上一篇我们简单实现了一个MVP的构架,下面我们来做一个简单的封装使其使用更简单方便 源码地址RxMVP分支Tag03 最终实现目录结构如下 BasePresenter 如果每一个Activity都需要 ...

  2. Eclipse.ini參数设置(Maven Integration for Eclipse JDK Warning)

    安装EclipseMaven插件后,Eclipse启动问题:Maven Integration for Eclipse JDK Warning.  解决方法: 1. 设置Eclipse使用的JRE为本 ...

  3. 基于Teigha.Net实现CAD到SHP的转换方案

    CAD在测绘领域运用广泛,所以,现在有很多成果都是CAD格式,但其自身存在很多局限性,需将其转为支持更加广泛,存储更加完善的 SHP文件.ArcGIS中直接提供相关转换工具,但不能转换Xdata,Ar ...

  4. Adobe Dynamic Http Streaming的简单配置与实现 (FMS, HLS, HDS)

    http://blog.csdn.net/avsuper/article/details/7663879 Adobe的Http Dynamic Streaming是针对苹果的HLS方案提出基于HTTP ...

  5. Android获取网络图片应用示例

    1.养成好习惯,配置字符串资源文件 strings.xml <?xml version="1.0" encoding="utf-8"?> <r ...

  6. Oracle function实现根据输入的日期以及天数,获取此日期之后的天数的工作日

    前提:在法定节日表(t_fdjr )中维护法定节日包括周六周天 /** * 功能描述:根据输入的日期以及天数,获取此日期之后的天数的工作日 * 输入参数: * i_date YYYY-MM-DD * ...

  7. Eclipse的tomcat插件

    下载Tomcat Eclipse插件 http://www.eclipsetotale.com/tomcatPlugin.html 或者我的网盘 将tomcatPluginV321.zip内容解压到 ...

  8. Linux内核3.11的socket busy poll机制避免睡眠切换

    Linux的网络协议栈很独立,上下通过两个接口分别和用户态以及设备相连.也能够看作是北向和南向接口...北向通过socket接口,南向通过qdisc接口(你能够觉得是上层的netdev queue,对 ...

  9. 怎么将txt文件转化为html格式的文件?--极为丑陋的方式

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #怎么将txt文件转化为html格式的文件?--极为丑陋的方式 import os #找出所有的txt格式的文 ...

  10. PmException--- SQL(统计报表)

    select TAGS,GROUP_CONCAT(TAGS) t from EXCEPTION_RESULT e,PM_TASK t ' and t.OWNER='admin' group by TA ...