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 proxy(不要问我为什么不知道)。

它解决了我的问题。

但如果它对你不起作用,也可以改变这个:

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

希望这能有所帮助。快乐编码:)

我也遇到过类似的问题,但我没有使用任何xml配置,所有的配置都是由spring引导自动配置的。

以下是我尝试做的/connect/facebook:

出现意外错误(类型=内部服务器错误,状态=500)。创建名为的bean时出错在类路径资源中定义了"scopedTarget.connectionRepository"[org/springframework/social/config/annotation/SocialConfiguration.class]:bean初始化失败;嵌套异常为org.springframework.aop.framework.AopConfigException:无法生成类[class的CGLIB子类org.springframework.social.connect.jdbc.JdbcConnectionRepository]:此问题的常见原因包括使用final类或不可见类;嵌套异常为org.springframework.cglib.core.CodeGeneration异常:java.lang.reflect.InvocationTargetException-->空

根本原因是类路径中存在spring boot devtools。删除devtools解决了问题。我还发现有人开了一个公关,请在那里留言,引起更多的关注。提取请求

Upd。PR被合并,从2.0.0.M1开始,开发工具不再有问题。

springboot项目有两种方法可以解决这个问题:

  1. 删除spring-boot-debtools依赖关系
  2. 在application.properties中设置spring.aop.proxy-target-class=false

我知道这篇文章很老了,但是除外

Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class ...把我带到这里。

对我来说,解决方案是一个默认的构造函数

我的解决方案是从类定义中删除最终

我在一些Rest控制器上使用PreAuthorize注释时遇到了同样的异常。问题是控制器类被定义为最终,这导致了这样的错误。

最新更新