복붙노트

[SPRING] 내 웹 앱의 봄부터 '스레드 바운드 요청 없음'오류 발생

SPRING

내 웹 앱의 봄부터 '스레드 바운드 요청 없음'오류 발생

내 웹 응용 프로그램에서 '스레드 바운드 요청 없음'오류가 발생하고 도움이 필요하다고 생각됩니다. 나는 struts2 + spring + hibernate를 사용하고, Spring을 사용하여 최대 절전 세션 팩토리를 관리하고, 내 struts 액션에 최대 절전 모드 세션을 주입하려고한다. 나는 그것이 의미가 있기를 바란다. 앱이 시작될 때 오류는 없지만 처음 웹 요청을하면 'No thread-bound request found'오류가 발생합니다. 여기에 내 봄 설정 :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
  <bean id="hibernateSessionFactory" scope="singleton"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  </bean>
  <bean id="hibernateSession" factory-bean="hibernateSessionFactory"
    factory-method="openSession" destroy-method="close" scope="request" class="org.hibernate.Session" />
</beans>

내 행동은 다음과 같습니다.

package actions.events;
import org.hibernate.Session;

public class Listing {
  Session session;
  public void setHibernateSession(Session value) throws Exception
  {
    session = value;
  }

  public String execute() {
    return "success";
  }
}

내 유일한 단서는 위의 'setHibernateSession'함수를 제거하면 액션이 하나 (게으른 인스턴스 생성)가 필요하지 않으면 스프링이 세션 생성을 방해하지 않으므로 오류가 발생하지 않는다는 것입니다.

그리고 여기 예외가 있습니다 :

Unable to instantiate Action, actions.events.Listing, defined for 'Listing' in namespace '/events'Error creating bean with name 'hibernateSession': Scope 'request' 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:307)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Unknown Source)

아, 그리고 내 web.xml에는 필요한 컨텍스트 리스너가 있으므로 http 요청은 struts에 의해 인식되어야합니다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app ...
  ...
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  ...
</web-app>

해결법

  1. ==============================

    1.Spring MVC없이 요청 범위를 사용하려면 web.xml에 RequestContextListener를 선언해야한다 (3.5.4.1. 초기 웹 설정 참조).

    Spring MVC없이 요청 범위를 사용하려면 web.xml에 RequestContextListener를 선언해야한다 (3.5.4.1. 초기 웹 설정 참조).

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

    2.XML 대신 Java를 사용하여 응용 프로그램을 구성하는 경우 동일한 conf가 다음에 적용될 수 있습니다.

    XML 대신 Java를 사용하여 응용 프로그램을 구성하는 경우 동일한 conf가 다음에 적용될 수 있습니다.

     public void onStartup(ServletContext servletContext) throws ServletException {
              //add listener
              servletContext.addListener(new RequestContextListener());
    
  3. from https://stackoverflow.com/questions/2039522/getting-a-no-thread-bound-request-found-error-from-spring-in-my-web-app by cc-by-sa and MIT license