Announcement Announcement Module
Collapse
No announcement yet.
Unable to configure scoped-proxy in a session scoped bean. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 http://static.springsource.org/sprin...nce/beans.html (section 3.4.4.5)

    What am I doing wrong. Thanks in advance.

    Code:
      	<bean id="HibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
      		<constructor-arg ref="SessionFactory"/>
      	</bean>
    
    	<bean id="custDataSourcePopulator" class="com.workscape.spring.postprocessor.DataSourcePostProcessor">
    		<property name="customerContext" ref="customerContext"/>
    	</bean>
    
    	<bean id="CustDataSource" class="com.workscape.spring.FillableBasicDataSource" destroy-method="close" scope="session">
        	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        	<aop:scoped-proxy/>
      	</bean>
    
      	<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">
          		<list>
            		<value>com.workscape.admin.model.Customer</value>
          		</list>
       		</property>
        	<property name="hibernateProperties">
          		<value>
            		hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
          		</value>
        	</property>
      	</bean>
    The exception is here...
    Code:
    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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
            at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
            at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
            at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
            at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
            at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
            at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
            at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
            at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
            at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
            at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
            at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
            at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
            at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
            at org.apache.catalina.core.StandardService.start(StandardService.java:516)
            at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
            at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
            at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Last edited by smadarapu; Feb 5th, 2010, 10: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?

    Comment


    • #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.

      Comment

      Working...
      X