Spring AOP错误:无法代理目标类,因为CGLIB2不可用

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 21:01   3428   0

在Spring AOP中,必须将cglib库包含到构建路径中,以避免出现“ 由于CGLIB2不可用而无法代理目标类 ”的错误消息。

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerServiceProxy': FactoryBean threw exception on object creation; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:127)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116)
 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:91)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:217)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
 at com.mkyong.common.App.main(App.java:14)
Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
 at org.springframework.aop.framework.DefaultAopProxyFactory.createAopProxy(DefaultAopProxyFactory.java:67)
 at org.springframework.aop.framework.ProxyCreatorSupport.createAopProxy(ProxyCreatorSupport.java:106)
 at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstance(ProxyFactoryBean.java:317)
 at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:243)
 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:121)
 ... 9 more

您可以从…下载cglib库。

1. Cglib官方网站
http://cglib.sourceforge.net/

2. Maven资料库
http://repo1.maven.org/maven2/cglib/cglib/2.2/

如果使用的是Maven,则可以仅包含Maven依赖项。

<!-- AOP dependency -->
    <dependency>
     <groupId>cglib</groupId>
 <artifactId>cglib</artifactId>
 <version>2.2</version>
    </dependency>

翻译自: https://mkyong.com/spring/spring-aop-error-cannot-proxy-target-class-because-cglib2-is-not-available/

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP