Announcement Announcement Module
No announcement yet.
Unable to configure scoped-proxy in a session scoped bean. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to configure scoped-proxy in a session scoped bean.

    I am not sure which forum i need to go to for this to be answered. Also posted in the "Web" forum.

    When I tried to configure a session scoped bean as a scoped-proxy i am seeing some exceptions. Below is my configuration. I followed the steps given in the documentation at (section

    What am I doing wrong. Thanks in advance.

      	<bean id="HibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
      		<constructor-arg ref="SessionFactory"/>
    	<bean id="custDataSourcePopulator" class="com.workscape.spring.postprocessor.DataSourcePostProcessor">
    		<property name="customerContext" ref="customerContext"/>
    	<bean id="CustDataSource" class="com.workscape.spring.FillableBasicDataSource" destroy-method="close" scope="session">
        	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
      	<bean id="CustSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        	<property name="dataSource" ref="CustDataSource"/>
        	<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
        	<property name="annotatedClasses">
        	<property name="hibernateProperties">
    The exception is here...
    main - 12:59:24,068 ERROR ContextLoader:215 - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustSessionFactory' defined in ServletContext resource [/WEB-I
    NF/spring/infrastructure-context.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'scopedTarget.CustDataSource': Scope 'session' is not active for the current thread; consider defining a scoped proxy fo
    r 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 actu
    ally operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In t
    his case, use RequestContextListener or RequestContextFilter to expose the current request.
            at Method)
            at org.springframework.web.context.ContextLoader.createWebApplicationContext(
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(
            at org.apache.catalina.core.StandardContext.listenerStart(
            at org.apache.catalina.core.StandardContext.start(
            at org.apache.catalina.core.ContainerBase.addChildInternal(
            at org.apache.catalina.core.ContainerBase.addChild(
            at org.apache.catalina.core.StandardHost.addChild(
            at org.apache.catalina.startup.HostConfig.deployDirectory(
            at org.apache.catalina.startup.HostConfig.deployDirectories(
            at org.apache.catalina.startup.HostConfig.deployApps(
            at org.apache.catalina.startup.HostConfig.start(
            at org.apache.catalina.startup.HostConfig.lifecycleEvent(
            at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
            at org.apache.catalina.core.ContainerBase.start(
            at org.apache.catalina.core.StandardHost.start(
            at org.apache.catalina.core.ContainerBase.start(
            at org.apache.catalina.core.StandardEngine.start(
            at org.apache.catalina.core.StandardService.start(
            at org.apache.catalina.core.StandardServer.start(
            at org.apache.catalina.startup.Catalina.start(
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(
            at java.lang.reflect.Method.invoke(
            at org.apache.catalina.startup.Bootstrap.start(
            at org.apache.catalina.startup.Bootstrap.main(
    Last edited by smadarapu; Feb 5th, 2010, 09:00 AM. Reason: The original post was copied from web forum, and that was a reply to another post and refers to it.

  • #2
    any ideas, any body?


    • #3
      After lots of debugging i found this. Thought might be useful for others.

      In my configuration, CustDataSource is session scoped and CustSessionFactory is default (singleton) scoped.

      At server start-up, spring framework creates a proxy data source. Then tries to create the session factory instance with a reference to the proxy data source. But when creating the session factory, the SettingsFactory class tries to get a connection to load some metadata. At this point the proxy tries to create an actual instance of data source and fails.

      There are couple of solutions i can think of.

      1) Make the session factory also session scoped. I tried and this works. I would like it to be a singleton, but there is no option.

      2) The SettingsFactory has this magic property "hibernate.temp.use_jdbc_metadata_defaults" which is true by default, if I set this to false there will be no attempt to get a connection and load the metadata. But I am not sure if that is a good idea, I dont know what the consequences would be. If anybody know please let me know.

      At this point I am going with option 1 didn't even try the 2nd option.