Spring Social - Could not generate CGLIB subclass
Asked Answered
E

5

5

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.

Ember answered 28/12, 2013 at 21:16 Comment(1)
I know it's an old question but how did you solve?Ethbin
R
5

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

Ramrod answered 17/11, 2014 at 7:51 Comment(1)
Hi vefthym, i modified my answer and explain it the best way i can, please consider it for a up vote.Ramrod
R
4

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.

Reddy answered 17/1, 2017 at 20:29 Comment(0)
I
2

there is two methods to slove this problem for springboot project:

  1. removing spring-boot-debtools dependency.
  2. setting spring.aop.proxy-target-class=false in your application.properties.
Inoculation answered 17/9, 2019 at 3:28 Comment(1)
this issue -> github.com/spring-projects/spring-social/issues/232Inoculation
U
1

I know this post is very old, however, the exception

Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class ... brought me here.

The solution for me was a default constructor.

Underwrite answered 8/10, 2021 at 12:1 Comment(1)
Can you show a peace of code that you make to solve your issue ?Councillor
D
0

The solution for me was to remove final from class definition.

I got the same exception while using PreAuthorize annotation on some Rest Controllers. The problem was that the controller classes where defined as final and it caused such error.

Dismount answered 18/1, 2023 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.