title: Hibernate collection is not associated with any session
body: <p>I have found several questions and answers with regard to this issue on SO, but they all seem to cover one major cause of the problem: fetching a collection outside of a transaction or within another transaction.  But in my case, I am fetching within the same transaction when fetching a parent object and collection. </p>
  
  <pre><code>@Service
  @Transactional
  public class IntegrationServiceImpl implements IntegrationService {
  @Override
      public Integration getIntegrationByIdFetchBackendParameters(Long integrationId) {
          Integration integration = integrationDao.get(integrationId);
          //not all integrations have to have backend.
          if (integration.getBackend() != null) {
              Hibernate.initialize(integration.getBackend().getBackendParameters());
          }
          return integration;
      }
  ...
  </code></pre>
  
  <p>But when it comes to Hibernate.initialize this branch in  org.hibernate.collection.internal.AbstractPersistentCollection
  is executed </p>
  
  <pre><code>if ( session == null ) {
                  throw new HibernateException( "collection is not associated with any session" );
              }
  </code></pre>
  
  <p>I cant see why <code>session</code> is <code>null</code>. Would someone explain this and suggest a solution? </p>
  
  <p><strong>EDIT 1 - Full stack trace</strong></p>
  
  <pre><code>org.hibernate.HibernateException: collection is not associated with any session
          at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:676)
          at org.hibernate.Hibernate.initialize(Hibernate.java:77)
          at com.dhl.finFw.service.IntegrationServiceImpl.getIntegrationByIdFetchBackendParameters(IntegrationServiceImpl.java:169)
          at com.dhl.finFw.web.integration.IntegrationOverviewManagedBean.loadIntegration(IntegrationOverviewManagedBean.java:59)
          at com.dhl.finFw.web.integration.AbstractIntegrationManagedBean.initCommonFields(AbstractIntegrationManagedBean.java:69)
          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 org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:344)
          at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:295)
          at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:399)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1481)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
          at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:333)
          at com.dhl.finFw.spring.scope.ViewScope.get(ViewScope.java:30)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:329)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
          at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
          at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:56)
          at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
          at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
          at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
          at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
          at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
          at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
          at org.apache.el.parser.AstValue.getValue(AstValue.java:161)
          at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
          at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
          at com.sun.faces.facelets.tag.jstl.core.ForEachHandler.apply(ForEachHandler.java:161)
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
          at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:166)
          at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
          at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:358)
          at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
          at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:120)
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
          at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:106)
          at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:178)
          at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
          at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
          at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:111)
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
          at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
          at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187)
          at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
          at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:179)
          at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
          at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
          at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379)
          at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:358)
          at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
          at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
          at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
          at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
          at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:164)
          at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:870)
          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
          at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at com.dhl.finFw.web.filter.FileNotFoundFilter.doFilter(FileNotFoundFilter.java:40)
          at com.dhl.finFw.web.filter.FileNotFoundFilter.doFilter(FileNotFoundFilter.java:35)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
          at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
          at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:64)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
          at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
          at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
          at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
          at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
          at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
          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:724)
  </code></pre>
  
  <p><strong>Edit 2 - configuration</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xsi:schemaLocation="
          http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;bean id="environmentVariablesConfiguration"
            class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig"&gt;
          &lt;property name="algorithm" value="PBEWithMD5AndDES" /&gt;
          &lt;property name="passwordSysPropertyName" value="APP_ENCRYPTION" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="configurationEncryptor"
            class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"&gt;
          &lt;property name="config" ref="environmentVariablesConfiguration" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="propertyConfigurer"
            class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer"&gt;
          &lt;constructor-arg ref="configurationEncryptor" /&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;${finFw.config.location}finFwUI.properties&lt;/value&gt;
                  &lt;value&gt;classpath:application.properties&lt;/value&gt;
                  &lt;value&gt;classpath:dateTime.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/&gt;
      &lt;/bean&gt;
  
      &lt;context:component-scan base-package="com.dhl.finFw"/&gt;
  
      &lt;context:annotation-config/&gt;
  
      &lt;tx:annotation-driven/&gt;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="persistenceUnitName" value="FINFW"/&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="generateDdl" value="${finFwUI.orm.generateDdl:false}"/&gt;
                  &lt;property name="showSql" value="${finFwUI.orm.showSql:false}"/&gt;
                  &lt;property name="databasePlatform" value="${finFwUI.orm.dialect}"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
  
      &lt;aop:aspectj-autoproxy/&gt;
  
      &lt;bean class="org.springframework.beans.factory.config.CustomScopeConfigurer"&gt;
          &lt;property name="scopes"&gt;
              &lt;map&gt;
                  &lt;entry key="view"&gt;
                      &lt;bean class="com.dhl.finFw.spring.scope.ViewScope"/&gt;
                  &lt;/entry&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.web.context.support.ServletContextAttributeExporter"&gt;
          &lt;property name="attributes"&gt;
              &lt;map&gt;
                  &lt;entry key="finFwUIEnvironment" value="${finFwUI.environment}" /&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="eventListenerBean" class="com.dhl.finFw.spring.FinFwApplicationListener" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
      &lt;display-name&gt;FinFwUI&lt;/display-name&gt;
      &lt;description&gt;Financial Framework Configuration&lt;/description&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;fileServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.dhl.finFw.web.FileServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;!-- Location of the Log4J config file, for initialization and refresh checks.
          Applied by Log4jConfigListener. The variable is replaced with System property 
          at runtime. --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;${finFw.config.location}log4j-finFwUI.properties&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;!-- Application version. The variable is replaced during Maven build. --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;applicationVersion&lt;/param-name&gt;
          &lt;param-value&gt;${applicationVersion}&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;primefaces.THEME&lt;/param-name&gt;
          &lt;param-value&gt;dhl&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.FACELETS_SKIP_COMMENTS&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.FACELETS_LIBRARIES&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/springsecurity.taglib.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- possible values: Development, Production, SystemTest, UnitTest The 
          variable is replaced during Maven build or set as System property during 
          development. --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;${finFwUI.jsf.stage}&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;!-- Spring application context config locations --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              classpath:com/dhl/finFw/finFwUI-core.xml
              classpath:com/dhl/finFw/finFwUI-dataSource.xml
              classpath:com/dhl/finFw/finFwUI-security.xml
              classpath:com/dhl/finFw/finFwUI-forms.xml
              classpath:com/dhl/finFw/finFwUI-audit.xml
          &lt;/param-value&gt;
      &lt;/context-
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;60&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;!-- Configures Log4J for this web app. As this context specifies a context-param
          "log4jConfigLocation", its file path is used to load the Log4J configuration. --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;!-- Starts Spring application context. The parent one. The web context 
          is started by Dispatcher servlet. --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;fileServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/file/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;/pages/protected/index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;encoding-filter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;encoding&lt;/param-name&gt;
              &lt;param-value&gt;UTF-8&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;fileNotFoundFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;com.dhl.finFw.web.filter.FileNotFoundFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;browserCacheControlFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;com.dhl.finFw.web.filter.BrowserCacheControlFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.primefaces.webapp.filter.FileUploadFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;/filter-mapping&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;encoding-filter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;fileNotFoundFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;browserCacheControlFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/pages/protected/integration/subscriptionScheduler.xhtml&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;error-page&gt;
          &lt;exception-type&gt;org.springframework.security.access.AccessDeniedException&lt;/exception-type&gt;
          &lt;location&gt;/pages/public/error/accessDenied.xhtml&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
          &lt;location&gt;/pages/public/error/internal.xhtml&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;500&lt;/error-code&gt;
          &lt;location&gt;/pages/public/error/internal.xhtml&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;404&lt;/error-code&gt;
          &lt;location&gt;/pages/public/error/notFound.xhtml&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;403&lt;/error-code&gt;
          &lt;location&gt;/pages/public/error/accessDenied.xhtml&lt;/location&gt;
      &lt;/error-page&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>ViewScope.java</strong></p>
  
  <pre><code>public class ViewScope implements Scope {
  
      private Logger logger = LoggerFactory.getLogger(getClass());
  
      public static final String VIEW_SCOPE_CALLBACKS = "viewScope.callbacks";
  
      @Override
      public Object get(String name, ObjectFactory&lt;?&gt; objectFactory) {
          Map&lt;String, Object&gt; viewMap = getViewMap();
          Object instance = viewMap.get(name);
          if (instance == null) {
              instance = objectFactory.getObject();
              synchronized (viewMap) {
                  viewMap.put(name, instance);
                  logger.debug("Bean '{}' has been put to ViewScope.", instance);
              }
          } else {
              logger.debug("Going to return an existing bean '{}'", instance);
          }
          return instance;
      }
  
  
      @Override
      public Object remove(String name) {
          Object instance = getViewMap().remove(name);
          if (instance != null) {
              Map&lt;String, Runnable&gt; callbacks = (Map&lt;String, Runnable&gt;) getViewMap().get(VIEW_SCOPE_CALLBACKS);
              if (callbacks != null) {
                  callbacks.remove(name);
                  logger.debug("Bean '{}' has been removed.", instance);
              }
          }
          return instance;
      }
  
      @Override
      public void registerDestructionCallback(String name, Runnable runnable) {
          Map&lt;String, Runnable&gt; callbacks = (Map&lt;String, Runnable&gt;) getViewMap().get(VIEW_SCOPE_CALLBACKS);
          if (callbacks != null) {
              callbacks.put(name, runnable);
              logger.debug("Registered callback for '{}'", name);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      @Override
      public Object resolveContextualObject(String name) {
          FacesContext facesContext = FacesContext.getCurrentInstance();
          FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
          return facesRequestAttributes.resolveReference(name);
      }
  
      @Override
      public String getConversationId() {
          FacesContext facesContext = FacesContext.getCurrentInstance();
          FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
          return facesRequestAttributes.getSessionId() + "-" + facesContext.getViewRoot().getViewId();
      }
  
      private Map&lt;String, Object&gt; getViewMap() {
          return FacesContext.getCurrentInstance().getViewRoot().getViewMap();
      }
  
  }
  </code></pre>