spring一些知识
来源:互联网 发布:淘宝达人账号简介 编辑:程序博客网 时间:2024/05/19 21:41
Spring容器配置
1.定义数据源(datasource)
2.通过依赖注入datasource创建sessionFactory
3.通过依赖注入sessionFactory创建hibernateTemplate
4.通过依赖注入hibernateTemplate创建dao
5.通过依赖注入dao创建service
6.通过依赖注入service创建action
配置事务控制
<tx:advice id="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<!-- 所有以browse、list、load、get及is开头的业务逻辑方法均不需要事务控制且只读 -->
<tx:method name="browse*"propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="list*"propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="load*"propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="get*"propagation="NOT_SUPPORTED" read-only="true"/>
<tx:method name="is*"propagation="NOT_SUPPORTED" read-only="true"/>
<!-- 设置所有方法均进行事务控制,如果当前没有事务,则新建一个事务-->
<tx:method name="*"propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 基于AOP技术的事务管理实现 -->
<aop:config>
<!--定义一个事务切入点,拦截com.eportal.service.impl包中所有类的所有方法-->
<aop:pointcut id="transactionPointcut"expression="execution(* com.eportal.service.impl.*.*(..))"/>
<!-- 引用txAdvice事务通知 -->
<aop:advisor advice-ref="txAdvice"pointcut-ref="transactionPointcut"/>
</aop:config>
Spring当中常用事务类型
REQUERED:支持当前事务,如果当前没有事务,则新建事务,常用
SUPPORTS:支持当前事务,如果当前没有事务,就以非事务方式执行
MANDATORY:支持当前事务,如果当前没有事务,就抛出异常
REQUIRES-NEW:新建一个事务,如果当前存在事务,则将当前事务挂起
NOT-SUPPORTED:以非事务方式执行,如果当前存在事务,则挂起当前事务
NEVER和NOT-SUPPORTED茶不错,以非事务方式执行,区别在于如果当前存在事务,则抛出异常
NESTED:如果当前存在事务,则嵌套在事务内执行;如果当前没有事务,则执行REQUIRED相同操作。
Table 4.3. Bean scopes
Scope Description
singleton (Default) Scopes a single bean definition to asingle object instance per Spring IoC container.
prototype Scopes a single bean definition to any number ofobject instances.
request Scopes a single bean definition to the lifecycle of asingle HTTP request; that is, each HTTP request has its owninstance of a bean created off the back of a single beandefinition. Only valid in the context of a web-aware SpringApplicationContext.
session Scopes a single bean definition to the lifecycle of anHTTP Session. Only valid in the context of a web-aware SpringApplicationContext.
global session Scopes a single bean definition to thelifecycle of a global HTTP Session. Typically only valid when usedin a portlet context. Only valid in the context of a web-awareSpring ApplicationContext.
- spring一些知识
- Spring MVC一些知识
- Spring MVC一些知识
- spring的一些知识
- 学习spring必须的一些知识
- 复习spring碰到的一些小知识
- 自己总结的Spring 的一些知识,Spring IOC,MVC
- 一些知识
- 一些知识
- 一些知识。。。
- spring知识
- spring知识
- Spring 框架知识知识总结
- 一些java入门知识
- .net的一些知识
- 环境变量的一些知识
- 内存的一些知识
- 一些java的知识
- 移动互联网入口论之超级 APP
- hibernate集合映射
- org.hibernate.exception.SQLGrammarException: could notinsert: [com.michael.model.Storen]
- el表达式
- Struts2的Stack Context和ValueStack
- spring一些知识
- 黑马程序员——GUI
- [自学问题总结]静态成员和非静态成员的区别
- struts2类型转换
- struts2标签不显示Label属性
- jsp自定义标签
- poj 2033 Alphacode
- Filter与Servlet的区别
- struts2 Action访问Servlet Api