Spring Social - Could not generate CGLIB subclass

skajake picture skajake · Dec 28, 2013 · Viewed 14.5k times · Source

I am getting the following error when attempting to navigate to the /connect endpoint of the spring social web module.

What I am getting:

[Request processing failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'scopedTarget.connectionRepository' 
defined in ServletContext resource [/WEB-INF/appContext.xml]: 
Initialization of bean failed; nested exception is 
org.springframework.aop.framework.AopConfigException: 
Could not generate CGLIB subclass of class 
[class org.springframework.social.connect.jdbc.JdbcConnectionRepository]: 
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]

Relevant portions of web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/appContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Relevant portion of appContext.xml:

<bean id="connectionFactoryLocator" 
          class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
        <property name="connectionFactories">
            <list>
                <bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
                    <constructor-arg value="${facebook.clientId}" />
                    <constructor-arg value="${facebook.clientSecret}" />                
                </bean>
            </list>
        </property>
    </bean>

    <bean id="usersConnectionRepository" 
          class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository">
        <constructor-arg ref="dataSource" />
        <constructor-arg ref="connectionFactoryLocator" />
        <constructor-arg ref="textEncryptor" />
    </bean>

    <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>

Thank you for any responses.

Answer

Krishnendu picture Krishnendu · Nov 17, 2014

I find this link useful https://github.com/socialsignin/socialsignin-showcase/issues/6, It solved my problem.

Basically in this case problem is with AOP proxy, for some reason CGLIB proxying not working in this case. so you have to turn it off and switch to JDK proxy. So what i did was just make this change in my context.xml -

<tx:annotation-driven transaction-manager="transactionManager" 
    proxy-target-class="true"/>

to

<tx:annotation-driven transaction-manager="transactionManager" 
    proxy-target-class="false"/>

By making proxy-target-class="false" spring will use JDK proxy (don't ask why i have no idea).

It's solved my problem.

But if it doesn't work for you, then also change this:

<security:global-method-security proxy-target-class="false" >

and this:

<bean id="connectionFactoryLocator" class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
    <property name="connectionFactories">
        <list>
            <bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
                <constructor-arg value="xxxxxxxxxxx" />
                <constructor-arg value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />             
            </bean>
        </list>
    </property>
    <aop:scoped-proxy proxy-target-class="false"/>
</bean>

Hope this helped. Happy coding :)