spring框架中添加HibernateInterceptor使得quartz可以调用Hibernate Session
来源:互联网 发布:java返回值怎么理解 编辑:程序博客网 时间:2024/05/21 20:53
1.spring
2.hibernate
3.quartz--定时调度工具,spring已经做了封装,也可以单独使用。
4.OpenSessionInViewFilter--web框架下的一个filter,能够让web request使用单一的hibernate session。
有的j2ee项目在web.xml文件中添加了OpenSessionInViewFilter,其目的是给web request提供单一的hibernate session,但是它也只能给web request提供hibernate session。也就是说,如果有某一个hibernate请求不是经由web request发起的,而是由quartz这样的定时任务发起的,那么quartz怎么样才能得到hibernate session呢?
解决办法就是使用HibernateInterceptor。当quartz发起hibernate session请求时,HibernateInterceptor会提供一个hibernate session给它。
配置文件如下:
<!-- Declaration of HibernateInterceptor -->
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- Manager template -->
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<ref bean="hibernateInterceptor"/>
</list>
</property>
</bean>
<!-- Sample Manager that encapsulates business logic -->
<bean id="userManager" parent="txProxyTemplate">
<property name="target">
<bean class="com.acme.service.impl.UserManagerImpl" autowire="byName"/>
</property>
</bean>
其中,<!-- Declaration of HibernateInterceptor -->部分定义了HibernateInterceptor;
<!-- Manager template -->部分定义了模板,并且加入了HibernateInterceptor;
<!-- Sample Manager that encapsulates business logic -->部分定义业务逻辑中的bean,记住,一定让他使用模板。
- spring框架中添加HibernateInterceptor使得quartz可以调用Hibernate Session
- Hibernate中可以直接来调用session,不需要工具类
- 使得任何Bean在Spring IOC容器中可以访问request、session、global Session作用域,RequestContextListener
- spring quartz hibernate no session 的问题
- SSH框架中 Spring设置定时器 Quartz
- SSH框架中 Spring设置定时器 Quartz
- spring中使用Quartz任务调度框架
- Spring框架中配置Quartz的教程
- spring 配置文件中添加Hibernate
- 新版本中spring与hibernate整合dao层调用session的方法
- 如果没添spring框架的情况下,Hibernate中session.connection()的替代方法
- 在Spring整合Hibernate的框架中,HibernateTemplate、SessionFactory和Session之间是怎样的关系?
- Spring整合的Hibernate的框架中,HibernateTemplate、SessionFactory和Session之间的关系
- 在spring,hibernate,struts2框架整合中出现的no session问题
- spring+hibernate+quartz
- Hibernate框架中Session的基本操作
- Quartz-任务调用框架
- Quartz-任务调用框架
- 网页技巧杂烩
- 实现树的checkbox 选择操作
- 关于阅读源代码
- 一个女孩写给女孩的话-不管是男是女看看吧,看看我们做了里面的多少
- NHibernate学习
- spring框架中添加HibernateInterceptor使得quartz可以调用Hibernate Session
- WCF 分布式事务的使用
- vi 里面没颜色
- 从网页中获取有用的信息 html2text
- 数据库:left join,right join,inner join
- EA1和B2Bi介绍
- 支持VC6.0的SDK包
- 把系统盘制作成ISO映像文件
- arm系统的中断解析