@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. 【网络文摘】Androidguy:当你的才华还无法撑起你的野心时,那么应该静下心来学习

    [序] 2013年12月初,接到51CTO的邀请写一篇关于挨踢人物传记的邀请.尽管写文章对我已不是什么新鲜事.数年来写的书和博客至少也在600万字以上.不过基本都是与技术有关的.写传记这还是头一次,也 ...

  2. 设计好玩的3D文字效果

    ​在线演示 本地下载 好玩的3D文字效果,可以替换汉字.快来试试吧!

  3. Navicat安装激活

    有条件的同学麻烦不要使用下面的激活步骤,仅供个人学习使用 ...... ...... ...... ...... 一.去官网下载最新Navicat软件https://www.navicat.com.c ...

  4. Java开发中所遇问题积累

    1.判断两个字符串是否相等时,如下,使用" == "无效: String name = "Jack"; if(name.equals("Jack&qu ...

  5. Internal Server Error: /favicon.ico 的解决方法

    项目大致环境:Linux + Apache + Django + Python 因为项目的需求重写了Python Logger.error 方法,每当记录错误日志的时候就发送一封邮件到指定的邮箱.项目 ...

  6. Java AES 加密工具类

    package com.microwisdom.utils; import java.security.NoSuchAlgorithmException; import java.security.S ...

  7. C# 编程实现串口通信

    http://blog.sina.com.cn/s/blog_6c67dab30101p3vn.html ----------------------------------------------- ...

  8. iOS CGRectGetMaxX/Y 使用

    在iOS的界面布局中我们能够使用CGRectGetMaxX 这种方法来方便的获取当前控件的x坐标值+宽度的数值.这样便能够方便布局. 同理CGRectGetMaxY是获取y坐标值+控件高度的值,当然这 ...

  9. H5中JavaScript常用代码片段

    /** * 批量替换方法,批量过滤特殊字符,通常用在通过后的各种编辑器添加的内容在App上编辑上使用 * james.wang 2016-11-11 * 使用方法:ReCont(Content,[&q ...

  10. NFS详解

    00.什么是 NFS (Network FileSystem) NFS 就是 Network FileSystem 的缩写,最早之前是由 sun这家公司所发展出来的. 他最大的功能就是可以透过网络,让 ...