Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-12402

Improve handling of missing JSF session in SessionScope

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.0.7
    • Fix Version/s: 4.3 RC2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      I have some JSF beans managed by Spring using @Configurable and compile time weaving.

      Then I have a session scoped bean:

      	<bean id="currentUser" factory-bean="authenticationUserService" factory-method="loadCurrentUser"
      		scope="session" lazy-init="true" />
      

      When Tomcat shuts down, it persists the active sessions.
      When it starts it tries to restore those sessions, which triggers this exception:

      SEVERE: Exception loading sessions from persistent storage
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settings.web.bean.Users': Injection of autowired d
      ependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private transient settings.model.User settings.web.bean.Users.currentUser; nested exception is java.lang.NullPointerException
              at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.j
      ava:293)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:384)
              at org.springframework.beans.factory.wiring.BeanConfigurerSupport.configureBean(BeanConfigurerSupport.java:141)
              at org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect.configureBean(AnnotationBeanConfigurerAspect.aj:63)
              at org.springframework.beans.factory.aspectj.AbstractDependencyInjectionAspect.ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractD
      ependencyInjectionAspect$3$6aa27052(AbstractDependencyInjectionAspect.aj:97)
              at org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect.ajc$interMethod$org_springframework_beans_factory_aspec
      tj_AbstractInterfaceDrivenDependencyInjectionAspect$org_springframework_beans_factory_aspectj_AbstractInterfaceDrivenDependencyInjectionAspect$ConfigurableDe
      serializationSupport$readResolve(AbstractInterfaceDrivenDependencyInjectionAspect.aj:117)
              at settings.web.bean.Users.readResolve(Users.java:1)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1104)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1807)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
              at java.util.HashMap.readObject(HashMap.java:1180)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
              at java.util.HashMap.readObject(HashMap.java:1180)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
              at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
              at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1619)
              at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1084)
              at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:282)
              at org.apache.catalina.session.StandardManager.load(StandardManager.java:202)
              at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:489)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
              at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5501)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
              at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
              at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1879)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
              at java.util.concurrent.FutureTask.run(FutureTask.java:262)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
              at java.lang.Thread.run(Thread.java:745)
      Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private transient settings.model.User settings.web.bean.Users.currentUser; nested exception is java.lang.NullPointerException
              at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcesso
      r.java:509)
              at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
              at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.j
      ava:290)
              ... 57 more
      Caused by: java.lang.NullPointerException
              at org.springframework.web.context.request.SessionScope.get(SessionScope.java:92)
              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:336)
              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1021)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:964)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862)
              at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcesso
      r.java:481)
              ... 59 more
      

      As there is no current request, this exception gets thrown.
      I'm hoping that a better way of handling this scenario can be implemented.

        Attachments

          Activity

            People

            Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            shadow Andrei Ivanov
            Last updater:
            Spring Issuemaster
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 40 weeks, 6 days ago