Announcement Announcement Module
Collapse
No announcement yet.
Could not generate CGLIB subclass Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not generate CGLIB subclass

    Hello everyone,

    I'm previously using spring-social m3 and now trying to use the spring social snapshot build. Here are my current configuration:

    1. Spring framework version 3.0.5
    2. Spring social build snapshot 20110615

    The problems is
    Code:
    Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:212)
    	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
    	at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:109)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1439)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1408)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	... 44 more
    Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    	at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721)
    	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:200)
    Here are my userConnectionRepository configuration
    Code:
    <bean id="usersConnectionRepository" class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository" scope="session">
    	<constructor-arg ref="dataSource" />
    	<constructor-arg ref="connectionFactoryLocator" />
    	<constructor-arg ref="textEncryptor" />
    	<aop:scoped-proxy/>
    </bean>
    Thanks in advance.

  • #2
    You'll need to change the <aop:scoped-proxy> to look like this:

    {code:java}
    <aop:scoped-proxy proxy-target-class="false" />
    {code}

    By default, <aop:scoped-proxy> will use CGLIB to subclass the target class and will require a default constructor. Setting proxy-target-class to "false" will tell it to use JDK dynamic proxies instead.

    I'm updating the documentation to reflect this.

    Comment


    • #3
      Hi Habuma,
      Thanks it's working now.

      Comment


      • #4
        Hi,

        I'm facing the same issue but without any luck..
        From the log I can see
        2011-09-21 23:13:58.074 DEBUG - Creating JDK dynamic proxy: target source is SimpleBeanTargetSource for target bean 'scopedTarget.usersConnectionRepository'
        2011-09-21 23:13:58.074 DEBUG - Creating JDK dynamic proxy: target source is SimpleBeanTargetSource for target bean 'scopedTarget.connectionRepository'

        but when I try to actually run the /connect/* controller I get the annoying ( ) error saying :

        "Caused by: org.springframework.aop.framework.AopConfigExcepti on: Could not generate CGLIB subclass of class [class org.springframework.social.connect.jdbc.JdbcConnec tionRepository]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given"

        although the previous log states that i'm working with JDK proxy, when spring injects the bean it tries to to do using cglib
        "at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhan cer.java:721) ~[cglib-nodep-2.2.jar:na]"



        Spring ver is 3.1.0.M2
        Social - 1.0.0.RELEASE
        Security : 3.1.0.RC3


        Anyone has some good advise? (I'm declaring the bean with <aop:scoped-proxy proxy-target-class="false"/>)

        Comment


        • #5
          You say that you're declaring the bean with <aop:scoped-proxy proxy-target-class="false"/>, but I'm wondering how your configuration compares to that of the spring-social-twitter4j sample (https://github.com/SpringSource/spri...ing/social.xml). That sample uses the XML-based configuration, so it should resemble what you have. It might be helpful if I could see what you're social configuration looks like.

          Comment


          • #6
            Hi Habuma,


            Thanks for the quick reply.

            I actually copied the social.xml..
            my code is

            <code>

            <bean id="connectionRepository" factory-method="createConnectionRepository" factory-bean="usersConnectionRepository" scope="request">
            <constructor-arg value="#{request.userPrincipal.name}"/>
            <aop:scoped-proxy proxy-target-class="false"/>
            </bean>


            <bean id="usersConnectionRepository" class="org.springframework.social.connect.jdbc.Jdb cUsersConnectionRepository">
            <constructor-arg ref="dataSource"/>
            <constructor-arg ref="connectionFactoryLocator"/>
            <constructor-arg ref="textEncryptor"/>
            <aop:scoped-proxy proxy-target-class="false"/>
            </bean>


            <bean id="connectionFactoryLocator" class="org.springframework.social.connect.support. ConnectionFactoryRegistry">
            <property name="connectionFactories">
            <list>
            <bean class="org.springframework.social.twitter.connect. TwitterConnectionFactory">
            <constructor-arg value="${integration.twitter.key}"/>
            <constructor-arg value="${integration.twitter.secret}"/>
            </bean>
            </list>
            </property>
            <aop:scoped-proxy proxy-target-class="false"/>

            </bean>
            </code>


            strangely as it seems, spring generate a jdk proxy (as i wrote in the previous post) but when it comes down to inject to the controller, it uses cglib..

            I'm fighting this for 2 days now (but i never backed down before!)

            The controller code is
            <code>

            <bean class="org.springframework.social.connect.web.Conn ectController">
            <constructor-arg name="connectionRepository" ref="connectionRepository"/>
            <constructor-arg name="connectionFactoryLocator" ref="connectionFactoryLocator"/>
            </bean>

            </code>



            any idea?
            btw - the social project rocks!


            Thanks,
            Yoni

            Comment


            • #7
              Hi,

              Just wanted to update you that the problem solved...
              Seems like I was missing one proxy-target-class declaration.. in my spring security configuration.

              All is good now!


              Thanks,
              Yoni

              Comment

              Working...
              X