Scope 'session' is not active for the current thread

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/woshirongshaolin/article/details/8251062

1、问题一

用struts2做查询,当不同客户端查询时,a端会看到b端的查询结果,导致原因scope="singleton"

解决方法:

要将bean中的scope设置成“session【session作用域的bean则对每次http Session有效

<bean id="assetAction" class="com.servicezone.itsd.asset.webapp.action.AssetAction"scope="session"
<property name="assetManager" ref="assetManager"/> 
<property name="itProductManager" ref="itProductManager"/> 
<property name="vendorManager" ref="vendorManager"/> 
    </bean>
于是出现如下异常

2、问题二

Struts Problem Report

Struts has detected an unhandled exception:

Messages:
  1. No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? 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.
  2. Error creating bean with name 'qAction': 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, or processing a request outside of the originally receiving thread? 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.
  3. Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction': 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, or processing a request outside of the originally receiving thread? 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.
File: org/springframework/web/context/request/RequestContextHolder.java
Line number: 131

Stacktraces

Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction':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, or processing a request outside of the originally receiving thread? 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.
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)

解决方法

(1)当使用了Spring's DispatcherServlet以外的Servlet 2.4及以上的Web容器时(如使用JSF或Struts),你需要在Web应用的'web.xml'文件中增加 javax.servlet.ServletRequestListener 定义
<web-app>
  ...
  <listener>

    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

  </listener>
  ...
</web-app>
(2)如果你用的是早期版本的web容器(Servlet 2.4以前的版本),那么你要使用一个javax.servlet.Filter的实现。请看下面的web.xml配置片段:

<web-app>
  ..
  <filter> 
    <filter-name>requestContextFilter</filter-name> 
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
  </filter> 
  <filter-mapping> 
    <filter-name>requestContextFilter</filter-name> 
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  ...
</web-app>
展开阅读全文

No Session found for current thread

02-09

在spring3.1整合hibernate4的时候出现No Session found for current thread,求大神看看是什么原因?rn[code=html]HTTP Status 500 - No Session found for current threadrnrntype Exception reportrnrnmessage No Session found for current threadrnrndescription The server encountered an internal error that prevented it from fulfilling this request.rnrnexceptionrnrnorg.hibernate.HibernateException: No Session found for current threadrn org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)rn org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024)rn com.hrmsys.dao.impl.BaseDaoImpl.getSession(BaseDaoImpl.java:20)rn com.hrmsys.dao.impl.BaseDaoImpl.findByProperty(BaseDaoImpl.java:117)rn com.hrmsys.dao.impl.UserDaoImpl.findByUsernameAndPassword(UserDaoImpl.java:16)rn com.hrmsys.service.impl.UserServiceImpl.validateUser(UserServiceImpl.java:24)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rn org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)rn org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)rn org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)rn $Proxy15.validateUser(Unknown Source)rn com.hrmsys.action.UserAction.login(UserAction.java:30)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)rn org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn[/code]rn这是applicationContext.xml里的sessionFactory里的代码rn[code=html]rn rn rn rn rn rn rn falsern org.hibernate.dialect.SQLServerDialectrn truern falsern org.springframework.orm.hibernate4.SpringSessionContextrn rn rn rn rn [/code] 论坛

org.hibernate.HibernateException: No Session found for current thread

01-11

这是applicationContext.xmlrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn /hbm/xml/Group/user.hbm.xmlrn /hbm/xml/Group/userMap.hbm.xmlrn /hbm/xml/Group/set_meal.hbm.xmlrn /hbm/xml/Group/card.hbm.xmlrn /hbm/xml/Group/history.hbm.xmlrn /hbm/xml/Group/action.hbm.xmlrn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn falsern truern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnuserDaornrnrnpublic class UserDao rn private SessionFactory sessionFactory;rn public User getUser(String name,String password)rn rn if(this.isHaveUser(name)&&this.isCorrectPwd(name, password))rn rn Query query=this.sessionFactory.getCurrentSession().createQuery("from User u where u.loginName=?");rn query.setString(0, name);rn @SuppressWarnings("rawtypes")rn List list=query.list();rn User user=(User)list.get(0);rn return user;rn rn return null;rn rn public SessionFactory getSessionFactory() rn return sessionFactory;rn rn public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rnrnrnrnrnrnHTTP Status 500 - No Session found for current threadrnrntype Exception reportrnrnmessage No Session found for current threadrnrndescription The server encountered an internal error that prevented it from fulfilling this request.rnrnexceptionrnrnorg.hibernate.HibernateException: No Session found for current threadrn org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)rn org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1041)rn user.hibernate.UserDao.getUser(UserDao.java:64)rn global.struts.LoginAction.execute(LoginAction.java:134)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn java.lang.reflect.Method.invoke(Method.java:601)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn rnrnrnrn求大侠解决,怎么回事! 论坛

Hibernate4 No Session found for current thread异常

10-07

标题:Hibernate4 No Session found for current thread与createQuery is not valid without active transaction异常n描述:n在项目程序运行时遇到了Hibernate4 No Session found for current thread异常,nn ![图片说明](https://img-ask.csdn.net/upload/201610/07/1475829970_705784.png)n百度了一下n在hibernate的配置文件中加入了threadn配置并且处理业务逻辑的类上也加入了注解如下nn package com.xiaonei.baseService;nnimport java.util.List;nnimport javax.annotation.Resource;nnimport org.hibernate.Query;nimport org.hibernate.Session;nimport org.hibernate.SessionFactory;nimport org.springframework.transaction.annotation.Transactional;nn@Transactionalnpublic class BaseServiceImpl implements BaseService nn @Resourcen private SessionFactory sessionFactory;n npublic SessionFactory getSessionFactory() n return sessionFactory;n nn public void setSessionFactory(SessionFactory sessionFactory) n this.sessionFactory = sessionFactory;n nn/**n * @author sunlongn * @param hql:传入的hql,可以带参数?n * @param args: 问号对应的参数数组n */n @Overriden public List getResult(String hql, Object[] args) nn Session session = sessionFactory.getCurrentSession();n System.out.println("执行到创建Session");n Query query = session.createQuery(hql);n System.out.println("执行到Query");n if(args!= null && args.length > 0)n for(int i = 0;ithreadn配置删除或者把值thread改成org.springframework.orm.hibernate3.SpringSessionContextn再次运行却又出现了org.springframework.orm.hibernate3.SpringSessionContext异常整了好久都没搞明白,这是为什么呀?n nnSpring 的配置文件n1.applicationContext.xml nn nn n n n n n n n n n n n n n n n n n nn n n n n nnn n n n n n n n n n n n n n nn n n n nn2.applicationContextbeans.xmlnnn n n n n n n n n n n n n n n n n n n nbaseServiceImpl.javanpackage com.xiaonei.service.baseService;nnimport java.util.List;nnimport javax.annotation.Resource;nnimport org.hibernate.Query;nimport org.hibernate.SessionFactory;nimport org.springframework.stereotype.Service;nimport org.springframework.transaction.annotation.Transactional;nn@Servicenpublic abstract class BaseServiceImpl implements BaseService nn @Resourcen private SessionFactory sessionFactory;n npublic SessionFactory getSessionFactory() n return sessionFactory;n nn public void setSessionFactory(SessionFactory sessionFactory) n this.sessionFactory = sessionFactory;n nn/**n * @author sunlongn * @param hql:传入的hql,可以带参数?n * @param args: 问号对应的参数数组n */n n n @Transactionaln public List getResult(String hql, Object[] args) nSystem.out.println("执行了getResult方法");n Query query = sessionFactory.getCurrentSession().createQuery(hql);n System.out.println("执行到createQuery方法");n if(args!= null && args.length > 0)n for(int i = 0;i calzz, Integer id) n // TODO Auto-generated method stubn return null;n nnnnnnnnnnnn 问答

[Thread]IllegalMonitorStateException : current thread not owner

08-29

//程序清单如下:rnrn//: c01:SingletonPattern.javarn// The Singleton design pattern: you canrn// never instantiate more than one.rnrn// Since this isn't inherited from a Cloneablern// base class and cloneability isn't added,rn// making it final prevents cloneability fromrn// being added through inheritance:rnrnfinal class Singletonrnrn //private static Singleton s = null;rn private int i;rn private static int referenceCount;rn private final static int referenceMax = 4;rn rn private Singleton(int x)rn rn i = x;rn rn rn public static synchronized Singleton getReference()rn throws ReferenceOverAgeExceptionrn rn Singleton s = null;rn rn if ( referenceCount < referenceMax )rn rn s = new Singleton(1);rn referenceCount ++;rn rn elsern rn throw new ReferenceOverAgeException("References are over age.");rn rn rn return s;rn rn rn public static synchronized Singleton getReference(long timeout)rn throws ReferenceOverAgeExceptionrn rn while ( true )rn rn long startTime = new java.util.Date().getTime();rn rn tryrn rn return getReference();rn rn catch (ReferenceOverAgeException e)rn rn Thread currentThread = Thread.currentThread();rn rn tryrn rn currentThread.wait(timeout); rn rn catch (InterruptedException ie)rn rn ie.printStackTrace();rn rn rn long endTime = new java.util.Date().getTime();rn rn if ( (endTime - startTime) >= timeout )rn rn throw new ReferenceOverAgeException("References are over age.");rn rn rn rn rn rn public int getValue()rn rn return i;rn rn rn public void setValue(int x)rn rn i = x;rn rnrnrnrnfinal class ReferenceOverAgeException extends RuntimeExceptionrnrn public ReferenceOverAgeException(String msg)rn rn super(msg);rn rn rn public ReferenceOverAgeException()rn rn rnrnrnrnpublic class SingletonPatternrnrn public static void main(String[] args)rn rn tryrn rn Singleton s1 = Singleton.getReference();rn System.out.println("s1");rn System.out.println("s1.i = "+s1.getValue());rn rn Singleton s2 = Singleton.getReference();rn s2.setValue(2);rn System.out.println("s2");rn System.out.println("s1.i = "+s1.getValue());rn System.out.println("s2.i = "+s2.getValue());rn rn Singleton s3 = Singleton.getReference();rn s3.setValue(3);rn System.out.println("s3");rn System.out.println("s1.i = "+s1.getValue());rn System.out.println("s2.i = "+s2.getValue()); rn System.out.println("s3.i = "+s3.getValue()); rn rn Singleton s4 = Singleton.getReference();rn s4.setValue(4);rn System.out.println("s4");rn System.out.println("s1.i = "+s1.getValue()); rn System.out.println("s2.i = "+s2.getValue()); rn System.out.println("s3.i = "+s3.getValue()); rn System.out.println("s4.i = "+s4.getValue()); rn rn Singleton s5 = Singleton.getReference(100);rn s5.setValue(5);rn System.out.println("s5");rn System.out.println("s1.i = "+s1.getValue()); rn System.out.println("s2.i = "+s2.getValue()); rn System.out.println("s3.i = "+s3.getValue()); rn System.out.println("s4.i = "+s4.getValue()); rn System.out.println("s5.i = "+s5.getValue());rn rn catch (ReferenceOverAgeException e)rn rn e.printStackTrace();rn rn rn tryrn rn // Can't do this: compile-time error.rn // Singleton s3 = (Singleton)s2.clone();rn rn catch(Exception e)rn rn e.printStackTrace(System.err);rn rn rn ///:~rnrnrn// 运行后结果如下:rns1rns1.i = 1rns2rns1.i = 1rns2.i = 2rns3rns1.i = 1rns2.i = 2rns3.i = 3rns4rns1.i = 1rns2.i = 2rns3.i = 3rns4.i = 4rnException in thread "main" java.lang.IllegalMonitorStateException: current threarnd not ownerrn at java.lang.Object.wait(Native Method)rn at org.javaresearch.jfml.designpatterns.Singleton.getReference(SingletonrnPattern.java:59)rn at org.javaresearch.jfml.designpatterns.SingletonPattern.main(SingletonPrnattern.java:132)rnrnrn// 请帮忙看看,问题出在哪里?如何解决?谢谢 论坛

大神都来看看吧!!!-Could not obtain transaction-synchronized Session for current thread

01-15

异常情况:rnException in thread "taskExecutor-1" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current threadrn at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)rn at cn.uihome.hibernate.dao.HibernateGenericDao.getCurrentSession(HibernateGenericDao.java:73)rn at cn.uihome.hibernate.dao.HibernateGenericDao.save(HibernateGenericDao.java:106)rn at cn.uihome.hibernate.basedao.BaseDao.save(BaseDao.java:187)rn at cn.uihome.service.noification.NotificationCommentManager.addNotificationComment(NotificationCommentManager.java:45)rn at cn.com.guju.util.notification.NotificationCommentUtil.updateNotification(NotificationCommentUtil.java:123)rn at cn.com.guju.util.notification.NotificationCommentUtil.addNotificationForCommented(NotificationCommentUtil.java:101)rn at cn.com.guju.aop.task.activity.AsyncActivityTask.run(AsyncActivityTask.java:32)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at java.lang.Thread.run(Thread.java:745)rnrn我是想在action里 开启一个新的线程,但这个线程涉及到Hibernate数据库的操作,所以报这个问题,求救大神给解决啊!!!!!! 论坛

Spring事务总是报org.hibernate.HibernateException: No Session found for current thread

04-23

rn 今天搞了一下spring mvc的注解,弄到数据库的时候,向数据库中存数据没办法存入成功,看一下错误代码是org.hibernate.HibernateException: No Session found for current thread,网上找了一些方法一直没解决,哪位帮忙看一下,代码如下 applicationContext-db.xml代码: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd" default-lazy-init="true"> init-method="init" destroy-method="close"> class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> org.hibernate.dialect.Oracle10gDialect true update 20 class="org.springframework.orm.hibernate4.HibernateTransactionManager"> spring-servlet.xml代码 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd" default-lazy-init="true"> class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />                                                                                                                               class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/test/" p:suffix=".jsp" /> class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8" />        web.xml       s3h3              contextConfigLocation         classpath:applicationContext*.xml                org.springframework.web.context.ContextLoaderListener                     log4jConfigLocation           /WEB-INF/log4j.properties                 spring         org.springframework.web.servlet.DispatcherServlet        contextConfigLocation /WEB-INF/classes/spring-servlet.xml      1         encoding org.springframework.web.filter.CharacterEncodingFilter encoding utf-8 encoding *.do encoding *.jspx encoding *.jhtml encoding *.html encoding *.htm encoding *.jsp          spring      *.do                index.jsp       rn  rn 问答

springMVC整合hibernate4时No Session found for current thread

05-15

今天在尝试着把springMVC和hibernate整合到一起, 搭建一个初始的框架, 用spring来管理hibernate的session. 现在sessionFactory已经可以成功注入, 但是在调用sessionFactory.getCurrentSession()方法时报错: [color=#FF0000]org.hibernate.HibernateException: No Session found for current thread[/color], 上网找了一些解决方案, 都没有解决这个问题, 我用的是声明式的注解, 下面贴图贴代码, 请各路英雄答疑解惑.rn工程整体结构: rn[img=https://img-bbs.csdn.net/upload/201405/15/1400117869_460824.jpg][/img]rnweb.xml: rn[code=text]rnrn S01rn rn redirect.jsprn rnrn rn contextConfigLocationrn classpath*:spring-core.xmlrn rnrn rn org.springframework.web.context.ContextLoaderListenerrn rnrn rn Introspector缓存清除监听器rn org.springframework.web.util.IntrospectorCleanupListenerrn rnrn rn rn dispatcherrn org.springframework.web.servlet.DispatcherServletrn rn contextConfigLocationrn classpath*:spring-servlet.xmlrn rn 1rn rn rn dispatcherrn *.dorn rnrn rn rn 字符集过滤器rn encodingFilterrn org.springframework.web.filter.CharacterEncodingFilterrn rn 字符集编码rn encodingrn UTF-8rn rn rn rn encodingFilterrn /*rn rnrn rnrn[/code]rnrnspring-core.xml:rn[code=text]rnrnrn rn rn rn rnrn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn com/deo/entity/User.hbm.xmlrn rn rn rn rn com.deo.entity.Mobilern rn rn rn rn org.hibernate.dialect.MySQL5Dialectrn updatern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rnrnspring-servlet.xml:rn[code=text]rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn /jsp/ rn rn rn .jsp rn rn rn rn rn[/code]rnrnBaseDaoImpl.java :rn[code=java]package com.deo.dao.impl;rnrnimport java.io.Serializable;rnrnimport javax.annotation.Resource;rnrnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnimport org.springframework.stereotype.Repository;rnrnimport com.deo.dao.BaseDao;rnrn/**rn * BaseDao 实现rn * @author Deorn *rn */rn@Repository("baseDaoImpl")rnpublic class BaseDaoImpl implements BaseDao rn rn /**rn * 从spring上下文获取sessionFactoryrn */rn @Resource(name = "sessionFactory")rn private SessionFactory sessionFactory;rnrn /**rn * 保存实体rn */rn @Overridern public Object save(T t) rn Serializable result = getSession().save(t);rn return result;rn rnrn /**rn * 获取session, 该session可不显式关闭rn */rn @Overridern public Session getSession() rn return sessionFactory.getCurrentSession();rn rnrnrn[/code]rnrn控制台报错: rn[code=text]org.hibernate.HibernateException: No Session found for current threadrn at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:993)rn at com.deo.dao.impl.BaseDaoImpl.getSession(BaseDaoImpl.java:45)rn at com.deo.dao.impl.BaseDaoImpl.save(BaseDaoImpl.java:36)rn at com.deo.dao.impl.UserDaoImpl.addUser(UserDaoImpl.java:19)rn at com.deo.service.impl.UserServiceImpl.addUser(UserServiceImpl.java:40)rn at com.deo.controller.UserController.addUser(UserController.java:68)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at ........................[/code] 论坛

集成shiro 出现org.hibernate.HibernateException: No Session found for current thread

02-13

在Realm中,rn方法doGetAuthenticationInfo,通过sysUserService查询,执行正常rn方法doGetAuthorizationInfo,也是通过sysUserService查询,结果会报错:org.hibernate.HibernateException: No Session found for current threadrn同个类中,为什么一个正常,一个会报session找不到rnrn请各位大侠帮忙指点!rnrn[b]web.xml[/b]rn[code=text]rn rn shiroFilterrn org.springframework.web.filter.DelegatingFilterProxyrn rn rn shiroFilterrn /*rn rn rn[/code]rnrn[b]applicationContext-shiro.xml[/b]rn[code=text]rnrn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn /admin/logout.jsp = logoutrn /admin/work!** = perms["admin:work"]rn rn rn rnrn rn rn rnrn rn rn rn rn rnrn rn rn rn rn[/code]rnrnMyRealm.javarn[code=java]rnpublic class MyRealm extends AuthorizingRealm implements rnRealm, rnInitializingBean rn rn rn private SysUserService sysUserService;rnrn rn public MyRealm() rn super();rnrn rn rn rn /** rn * 认证信息 rn */ rn @Overridern protected AuthenticationInfo doGetAuthenticationInfo( rn AuthenticationToken authcToken ) throws AuthenticationException rn UsernamePasswordToken token = (UsernamePasswordToken) authcToken; rn String userName = token.getUsername(); rn if( userName != null && !"".equals(userName) ) 、rn//这个地方查询,执行正常rn SysUser user = sysUserService.login(token.getUsername(), String.valueOf(token.getPassword()));rn rn if( user != null ) rn return new SimpleAuthenticationInfo( rn user.getUserName(),user.getPassword(), getName()); rn rn return null; rn rnrn /** rn * 授权信息 rn */ rn @Overridern protected AuthorizationInfo doGetAuthorizationInfo( rn PrincipalCollection principals) rn rn String username = SecurityUtils.getSubject().getPrincipals().fromRealm(getName()).toString();rn rn rn if( username != null ) rn SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); rn//这个地方去查询,结果在dao会报错:org.hibernate.HibernateException: No Session found for current threadrn info.addRoles(sysUserService.findRoleByUser(user));rn return info; rn rn return null; rn rn rn rn public SysUserService getSysUserService() rn return sysUserService;rn rnrn public void setSysUserService(SysUserService sysUserService) rn this.sysUserService = sysUserService;rn rnrnrn @Overridern public void afterPropertiesSet() throws Exception rn Assert.notNull(sysUserService); rn // TODO Auto-generated method stubrn rn rn rnrn @Overridern public String getName() rn return getClass().getName();rn rnrn rn rn[/code] 论坛

spring3.2+hibernate4.2 整合 spring security报No Session found for current thread

04-30

[code="java"]rnpublic class SpringSecurityMetaDataSource implements FilterInvocationSecurityMetadataSource rn //@Resource(name = "resourceDao")rn private ResourceDao resourceDao;rn rn private static Map> resourceMap = null;rn rn @Autowiredrn public SpringSecurityMetaDataSource(ResourceDao resourceDao) rn this.resourceDao = resourceDao;rn loadResourceDefine();rn rnrnrn /**rn * 加载所有资源与权限的关系rn */rn @SuppressWarnings("unused")rn private void loadResourceDefine() rn if(resourceMap == null) rn resourceMap = new HashMap>(); rn List resources = this.resourceDao.listAll(ResourceManager.class);rn for (ResourceManager resource : resources) rn Collection configAttributes = new ArrayList(); rn //以权限名封装为Spring的security Object rn ConfigAttribute configAttribute = new SecurityConfig(resource.getName()); rn configAttributes.add(configAttribute); rn resourceMap.put(resource.getUrl(), configAttributes); rn rn rn rn Set>> resourceSet = resourceMap.entrySet();rn Iterator>> iterator = resourceSet.iterator();rn rn rnrnrn[/code]rnrn断点跟进去后发现:rnList resources = this.resourceDao.listAll(ResourceManager.class);rn是这抛出的错,报Caused by: org.hibernate.HibernateException: No Session found for current threadrnrn我怀疑 通过构造方法注入的resourceDao不受hibernate的事务管理,rn因此上诉代码改为了:rnrn[code="java"]rn @Resource(name = "resourceDao")rn private ResourceDao resourceDao;rn rn private static Map> resourceMap = null;rn rn @Autowiredrn public SpringSecurityMetaDataSource() rn loadResourceDefine();rn rn[/code]rnrn这样的话,又会报resourceDao为空指针错,rn详见代码附件。rnjar包如下:rnantlr-2.7.7.jarrnaopalliance-1.0.jarrnaspectjrt.jarrnaspectjweaver.jarrncommons-fileupload-1.3.jarrncommons-logging-1.1.2.jarrndom4j-1.6.1.jarrndruid-0.2.12.jarrnhibernate-commons-annotations-4.0.1.Final.jarrnhibernate-core-4.2.0.Final.jarrnhibernate-jpa-2.0-api-1.0.1.Final.jarrnjavassist-3.15.0-GA.jarrnjboss-logging-3.1.0.GA.jarrnjta-1.1.jarrnmysql-connector-java-5.1.21.jarrnspring-aop-3.2.2.RELEASE.jarrnspring-aspects-3.2.2.RELEASE.jarrnspring-beans-3.2.2.RELEASE.jarrnspring-context-3.2.2.RELEASE.jarrnspring-core-3.2.2.RELEASE.jarrnspring-expression-3.2.2.RELEASE.jarrnspring-jdbc-3.2.2.RELEASE.jarrnspring-orm-3.2.2.RELEASE.jarrnspring-security-config-3.2.0.M1.jarrnspring-security-core-3.2.0.M1.jarrnspring-security-web-3.2.0.M1.jarrnspring-tx-3.2.2.RELEASE.jarrnspring-web-3.2.2.RELEASE.jarrnspring-webmvc-3.2.2.RELEASE.jar 问答

java多线程current thread not owner 错误

08-13

[color=#FF0000]刚刚写了个多线程的程序,系统报current thread not owner错误,望各位大虾指点指点[/color]rn[color=#99CCFF]rnimport java.util.Queue;rnpublic class MyExec extends Thread rn private final Queue workQueue ;rn private final Object o ;rn private Runnable r = null;rnrn public MyExec(Queue queue,Object o) rn this.workQueue = queue;rn this.o = o;rn rn public void run() rn while (true) rn //从对列中拿取对象,开始执行run方法,队列为空就阻塞rn if (workQueue.isEmpty()) rn try rn [color=#FF0000]o.wait();//这个地方报异常[/color]rn catch (InterruptedException e) rn e.printStackTrace();rn rn rn r = workQueue.remove();rn r.run();rn rn rnrnrn客户端类:rnimport java.util.Queue;rnrnpublic class Client implements Runnable rn private Queue execQueue = null;rn private int i = 0;rn private final Object o ;rn public Client(Queue queue,Object o,int i)rn rn this.execQueue = queue;rn this.o =o;rn this.i = i;rn rn public void start()rn rn execQueue.add(this);rn o.notify();rn rn public void run() rn System.out.println("线程"+i+"开始运行");rn try rn Thread.sleep(10000);rn catch (InterruptedException e) rn e.printStackTrace();rn rn System.out.println("------------线程"+i+"运行结束退出");rn rnrnrnrn主线程类:rnimport java.util.Queue;rnimport java.util.concurrent.ConcurrentLinkedQueue;rnrnpublic class MainTest rnrn public static void main(String[] args) rn int execThreadNum = 10;rn int clientThreadNum = 200;rn final Object o = new Object();rn MyExec[] exec = new MyExec[execThreadNum];rn Client[] client = new Client[clientThreadNum];rn Queue workQueue = new ConcurrentLinkedQueue();rn for(int i= 0;i 论坛

Spring AOP进行日志管理时,日志记录Service报No Session found for current thread异常

05-21

如题,使用Spring AOP对service层进行日志记录,在日志记录类中调用dao层方法操作数据库,但是调用时一直报No Session found for current thread异常,配置文件如下,看起来好像是没有对LogService进行实物管理,导致没有注入SessionFactory,有没有人遇到过类似的情况,求指导。rnrnrn rn rn rn rnrn rn rn rn rn rn rn rn rnrn rn rn rnrn rn rn rnrn异常输出:rnorg.hibernate.HibernateException: No Session found for current threadrn at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:978)rn at com.gzzs.util.dao.BaseDaoImpl.getSession(BaseDaoImpl.java:19)rn at com.gzzs.util.dao.BaseDaoImpl.get(BaseDaoImpl.java:45)rn at com.gzzs.util.service.LogServiceImpl.test(LogServiceImpl.java:28)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)rn at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603)rn at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:39)rn at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn at com.sun.proxy.$Proxy11.ifHasResumes(Unknown Source)rn at com.gzzs.more.action.UserCenterAction.mgrLogin(UserCenterAction.java:650)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.gzzs.util.action.LoginInterceptor.intercept(LoginInterceptor.java:93)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Unknown Source) 论坛

No Scope registered for scope 'Singleton'

02-25

Struts Problem ReportrnStruts has detected an unhandled exception: rnrnMessages: No Scope registered for scope 'Singleton' rnUnable to instantiate Action, tc.mts.model.login.LoginAction, defined for 'login' in namespace '/base/login'No Scope registered for scope 'Singleton' rn rnFile: org/springframework/beans/factory/support/AbstractBeanFactory.java rnLine number: 295 rnrn[code=XML]rnStacktracesrnUnable to instantiate Action, tc.mts.model.login.LoginAction, defined for 'login' in namespace '/base/login'No Scope registered for scope 'Singleton' rn com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:306)rn com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:387)rn com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)rn org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)rn org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)rn com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:458)rn org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn tc.mts.common.RequestFilter.doFilter(RequestFilter.java:50)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)rn org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn java.lang.Thread.run(Unknown Source)rn rnjava.lang.IllegalStateException: No Scope registered for scope 'Singleton' rn org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:295)rn org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)rn tc.mts.util.SpringUtil.getBean(SpringUtil.java:18)rn tc.mts.model.login.LoginAction.(LoginAction.java:20)rn sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)rn sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)rn java.lang.reflect.Constructor.newInstance(Unknown Source)rn java.lang.Class.newInstance0(Unknown Source)rn java.lang.Class.newInstance(Unknown Source)rn com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:119)rn com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)rn com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)rn com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)rn com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:287)rn com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:387)rn com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)rn org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)rn org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)rn com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:458)rn org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn tc.mts.common.RequestFilter.doFilter(RequestFilter.java:50)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)rn org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn java.lang.Thread.run(Unknown Source)rnrnrn[/code]rnrn错误信息如上,请大家帮助. 论坛

SpringMVC 4 + Hibernate 4启动完成调用Service报错No Session found for current thread

04-01

我为服务添加了onApplicationEvent来响应服务加载完成事件。rn并在事件中做一些初始化,初始化中有数据库操作,会报No Session found for current thread错误。麻烦帮忙看下。rnrn错误:rn[code=html]rn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.hibernate.HibernateException: No Session found for current threadrn at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:988)rn at com.ddm.core.base.dao.BaseDaoImpl.getSession(BaseDaoImpl.java:47)rn at com.ddm.core.base.dao.BaseDaoImpl.getCriteria(BaseDaoImpl.java:61)rn at com.ddm.core.base.dao.BaseDaoImpl.find(BaseDaoImpl.java:80)rn at com.ddm.core.base.dao.BaseDaoImpl.find(BaseDaoImpl.java:69)rn at com.ddm.core.base.dao.BaseDaoImpl.findAll(BaseDaoImpl.java:65)rn at com.ddm.core.base.service.BaseServiceImpl.list(BaseServiceImpl.java:56)rn at com.ddm.core.base.service.BaseServiceImpl$$FastClassBySpringCGLIB$$59e55cef.invoke()rn at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)rn at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)rn at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)rn at com.ddm.core.service.ModuleService$$EnhancerBySpringCGLIB$$554969ac.list()rn at com.ddm.core.utils.PermissionUtil.updatePermission(PermissionUtil.java:73)rn at com.ddm.core.listener.StartupListener.updatePermission(StartupListener.java:31)rn at com.ddm.core.listener.StartupListener.onApplicationEvent(StartupListener.java:23)rn at com.ddm.core.listener.StartupListener.onApplicationEvent(StartupListener.java:1)rn at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)rn at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)rn at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:776)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)rn at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)rn at java.util.concurrent.FutureTask.run(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)rn at java.lang.Thread.run(Unknown Source)rn[/code] 论坛

没有更多推荐了,返回首页