编程语言
首页 > 编程语言> > java – Spring Social – 无法生成CGLIB子类

java – Spring Social – 无法生成CGLIB子类

作者:互联网

尝试导航到spring社交网络模块的/ connect端点时,我收到以下错误.

我得到了什么:

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

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>

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>

感谢您的回复.

解决方法:

我觉得这个链接很有用https://github.com/socialsignin/socialsignin-showcase/issues/6,它解决了我的问题.

基本上在这种情况下问题是AOP代理,由于某种原因CGLIB代理在这种情况下不起作用.所以你必须将其关闭并切换到JDK代理.所以我所做的只是在我的context.xml中进行此更改 –

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

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

通过使proxy-target-class =“false”spring将使用JDK代理(不要问为什么我不知道).

它解决了我的问题.

但如果它不适合你,那么也改变这个:

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

还有这个:

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

希望这有帮助.快乐编码:)

标签:java,spring,spring-social
来源: https://codeday.me/bug/20190612/1226788.html