Results 1 to 3 of 3

Thread: Session scoped beans with constructor args

  1. #1
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Unhappy Session scoped beans with constructor args

    Hello again,

    I'm trying to get my AuthenticationManager being session scoped. I try to confiugre it as follows:
    Code:
    <bean id="AuthenticationManager" class="....AuthenticationManagerImpl" scope="session">
    	<constructor-arg ref="UserDAO" />
    	<aop:scoped-proxy />		
    </bean>
    and get

    Code:
    11:13:57,352 ERROR ContextLoader:205 - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AuthenticationManager': Initialization of bean failed; nested exception is null
    Caused by: 
    java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:718)
    	at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
    	at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
    	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    	at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:195)
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:150)
    	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:72)
    	at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:87)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:866)
    ...
    Seems like the Proxy doesn't forward the constructor argument. I rarely would like to switch to SetterInjection.

    Any Ideas?

    Regards
    Ollie

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by Oliver Schlicht
    Seems like the Proxy doesn't forward the constructor argument. I rarely would like to switch to SetterInjection.
    The scoped proxies are indeed CGLib proxies and don't support constructor arguments. I don't know about <aop:scoped-proxy/>, but with my setup it is possible to specify a property "proxyTargetClass" and set it to false, so that JDK dynamic proxies are generated and so constructor arguments are supported.

    The config should look similar to the following:

    Code:
      <bean id="AuthenticationManager" scope="singleton"
            class="org.springframework.aop.scope.ScopedProxyFactoryBean">
        <property name="proxyTargetClass" value="false"/>
        <property name="targetBeanName" value="AuthenticationManagerTarget"/>
      </bean>
    
      <bean id="AuthenticationManagerTarget" scope="session"
            class="....AuthenticationManagerImpl"/>
    There was a bug in former RC and milestone versions, where proxyTargetClass was disregarded, but it shall be fixed since RC 2: issue SPR-2021. I haven't tested it yet.

    As I said I don't know if <aop:scoped-proxy/> supports this feature as well, maybe it is as easy as specifying it as property to it as well.

    Jörg

  3. #3
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Default

    Thanks a lot, that seems to solve my problem. I do not depend on <aop:scoped-proxy />, your configuration works well.

    Regards,
    Ollie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •