会话使用JTA Transaction销毁事件

时间:2015-03-31 08:05:15

标签: spring session jboss

我正在研究JBOSS应用程序,我面临着loggin sessionTimeout事件的问题

我想在会话到期后进行JTA交易。

我的代码如下

spring.xml

...

<bean
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"
    id="transactionManager">
    <property name="sessionFactory" >
        <ref local="sessionFactory" />
    </property>
</bean>

<bean id="msg" class="com.Message">
    ....
</bean>

...

的web.xml

...

<listener>
    <listener-class>
        com.demo.MySessionListener
    </listener-class>
</listener>

...

类文件

public class MySessionListener implements HttpSessionListener{
    public void sessionCreated(HttpSessionEvent event) {
    }

    public void sessionDestroyed(HttpSessionEvent event) {
        HttpSession session = event.getSession();
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
        Message msg = (Message)ctx.getBean("msg");
        msg.save();    //    throws error org.springframework.transaction.CannotCreateTransactionException
    }

}

我发现所有JTA操作都必须在会话中完成,但在这种情况下我该如何实现呢?因为会话到期事件我想执行JTA事务。

让我知道是否有人甚至在此之前解决了这个问题。

由于

栈跟踪


at org.jboss.web.tomcat.service.session.ClusteredSession.removeAttributeInternal(ClusteredSession.java:1292)
    at org.jboss.web.tomcat.service.session.ClusteredSession.expire(ClusteredSession.java:844)
    at org.jboss.web.tomcat.service.session.ClusteredSession.expire(ClusteredSession.java:740)
    at org.jboss.web.tomcat.service.session.ClusteredSession.isValid(ClusteredSession.java:720)
    at org.jboss.web.tomcat.service.session.ClusteredSession.isValid(ClusteredSession.java:685)
    at org.jboss.web.tomcat.service.session.JBossCacheManager.processExpires(JBossCacheManager.java:1236)
    at org.jboss.web.tomcat.service.session.JBossManager.backgroundProcess(JBossManager.java:817)
    at org.jboss.web.tomcat.service.session.JBossCacheManager.backgroundProcess(JBossCacheManager.java:1185)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1270)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1555)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1564)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1564)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1544)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workContext': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:661)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:611)
    at com.ideas.carparkpro.commons.bean.CproWorkContext$$EnhancerByCGLIB$$ef8de176.getDataSource()
    at com.ideas.carparkpro.core.util.UserRoutingDataSource.determineCurrentLookupKey(UserRoutingDataSource.java:103)
    ... 30 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:102)
    at org.springframework.web.context.request.SessionScope.get(SessionScope.java:88)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:285)
    ... 36 more

0 个答案:

没有答案