Spring Framework
  1. Spring Framework
  2. SPR-5011

how to use session scoped bean, getting errors

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I am using spring 2.0. I created a bean and tried to give it session scope by following entry in beans xml file.

      <bean id="reportManager" scope="session"
      class="com.ml.lrt.re.frontend.reportmanager.ReportManagerFacade">
      </bean>

      but i get error related to listener and when i add the listener

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

      the class RequestContextListener is not available. In which jar is this class present?

      After this i changed the code to use

      <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
      </listener> in web.xml and it compiled.

      but after this i get another error java.lang.IllegalStateException: No Scope registered for scope 'session'

      for this i found that i need to modify my entry in beans xml to

      <bean id="reportManager" scope="session"
      class="com.ml.lrt.re.frontend.reportmanager.ReportManagerFacade">
      <aop:scoped-proxy/>
      </bean>

      but i still get the error for CGLIB. i found on net that even after using cglib u get errors.

      how can i create a session scoped bean in spring?

        Activity

        Hide
        Juergen Hoeller added a comment -

        The official class name for the RequestContextListener is "org.springframework.web.context.scope.RequestContextListener", so that's what you'll need to use (as you figured). Note that request and session scope will only work in a WebApplicationContext, as bootstrapped by Spring's ContextLoaderListener (i.e. it won't work in a plain ClassPathXmlApplicationContext, for example). Scoped proxies are required when accessing scoped beans from singleton beans; if you reobtain your scoped beans for each request, no such scoped proxy setup is required. CGLIB proxies should work fine when following the general rules for classes that support CGLIB proxying.

        In general, this is not a bug. Please just create bug reports for actual bugs, not for finding out how to use a specific facility. For the latter kind of question, please use our forums at http://forum.springframework.org.

        Juergen

        Show
        Juergen Hoeller added a comment - The official class name for the RequestContextListener is "org.springframework.web.context.scope.RequestContextListener", so that's what you'll need to use (as you figured). Note that request and session scope will only work in a WebApplicationContext, as bootstrapped by Spring's ContextLoaderListener (i.e. it won't work in a plain ClassPathXmlApplicationContext, for example). Scoped proxies are required when accessing scoped beans from singleton beans; if you reobtain your scoped beans for each request, no such scoped proxy setup is required. CGLIB proxies should work fine when following the general rules for classes that support CGLIB proxying. In general, this is not a bug. Please just create bug reports for actual bugs, not for finding out how to use a specific facility. For the latter kind of question, please use our forums at http://forum.springframework.org . Juergen

          People

          • Assignee:
            Unassigned
            Reporter:
            swarna dhakad
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              5 years, 40 weeks, 1 day ago