懒得笔记5 spring aop 整合hibernate 事务管理
来源:互联网 发布:网络借贷公司怎么注册 编辑:程序博客网 时间:2024/04/29 17:38
1,在xml 中加上
a) 加上对应的xsd文件spring-aop.xsd
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"
b) beans.xml <aop:aspectj-autoproxy /> // 表明自动产生代理
2,
后面三个包。。不然各种错。。不知道要怎么样才知道要导入哪种包。
3,annotation 和 xml 两种方式
xml要掌握
4,spring 整合 hibernate
a, 引入 data common 包 hibernate 等。。。根据报的错去导入
b, 生成sessionFactory
spring 整合 hibernate使用annotation
<bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /> <!-- sessionFactory 织入对象 --><property name="annotatedClasses"> <!-- 指明数据对象 --><list><value>com.model.User</value><value>com.model.Log</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>
声明式的事务管理
a, 加入
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
b, 加入
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
c , 在事务的地方加上
@Transactional(readOnly=true) 如
@Transactional public void add(User user) {userDAO.save(user);Log log = new Log();log.setMsg("a user saved!");logDAO.save(log);}例子 点击打开链接
使用xml
<?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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"><context:annotation-config /><context:component-scan base-package="com" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><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><context:property-placeholder location="jdbc.properties" /> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /> <!-- sessionFactory 织入对象 --><property name="annotatedClasses"> <!-- 指明数据对象 --><list><value>com.model.User</value><value>com.model.Log</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> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="add*"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="bussinessService" expression="execution(* com.service..*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/> </aop:config></beans>
packagetoscan
- 懒得笔记5 spring aop 整合hibernate 事务管理
- 懒得笔记6 spring hibernate template
- Spring整合Hibernate的事务管理
- Spring--hibernate整合_事务管理
- Spring声明式事务管理、Spring整合Hibernate
- Spring声明式事务管理、Spring整合Hibernate
- Spring声明式事务管理、Spring整合Hibernate
- 使用Spring-Aop实现Hibernate事务管理
- spring 集成hibernate事务管理(aop实现)
- Spring框架(二)整合Junit4、AOP开发、AOP事务管理详解
- spring整合hibernate的声明式事务管理
- Spring整合Hibernate 声明式的事务管理
- 懒得笔记4 spring annotation
- spring整合ibatis事务管理(各种AOP,比较乱)
- 传智播客--Spring中的事务管理,hibernate整合,struts整合(佟刚)
- Spring中的事务管理,hibernate整合,struts整合(佟刚)
- Spring+Hibernate整合时关于Hibernate事务管理的问题
- red5-hibernate-spring事务(aop)整合
- 快速求幂的最后一位
- 吸费电话招商 打电话就赚钱 加值电话平台
- C/C++中的作用域
- 电话群呼器 加值电话招商 年收入百万
- 电话吸费赚钱 小投资大回报 手机吸费
- 懒得笔记5 spring aop 整合hibernate 事务管理
- 关于指针和引用
- 揭秘响一声电话吸费 声讯电话平台
- RelativeLayout属性含义
- 概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM
- CMenu(弹出式菜单)
- window.frames[].location window.frames[].src
- C语言实现单链表增删查找等功能
- lis双工常见设置!