Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Social - Could not generate CGLIB subclass

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.

like image 419
skajake Avatar asked Dec 26 '22 15:12

skajake


2 Answers

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

like image 150
Krishnendu Avatar answered Dec 28 '22 05:12

Krishnendu


I had similar issue, however I didn't use any of xml configs, everything was autoconfigured by spring-boot.

Here is what I got trying to do a /connect/facebook:

There was an unexpected error (type=Internal Server Error, status=500). Error creating bean with name 'scopedTarget.connectionRepository' defined in class path resource [org/springframework/social/config/annotation/SocialConfiguration.class]: 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 org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null

The root cause was having spring-boot-devtools in the classpath. Removing devtools solved the problem. I also found a PR opened by some guy, please leave a comment there to bring more attention to the issue. pull request

Upd. the PR was merged and starting from 2.0.0.M1 there is no issue with dev-tools anymore.

like image 20
Vadim Kirilchuk Avatar answered Dec 28 '22 07:12

Vadim Kirilchuk