返回顶部

收藏

Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or speci

更多

在spring aop程序中出现了下面的异常信息 :

2014-6-2 9:08:51 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@80d1ff: startup date [Mon Jun 02 09:08:51 CST 2014]; root of context hierarchy
2014-6-2 9:08:51 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [appContext.xml]
2014-6-2 9:08:51 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c9b196: defining beans [org.springframework.aop.config.internalAutoProxyCreator,personService,simpleAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
2014-6-2 9:08:51 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c9b196: defining beans [org.springframework.aop.config.internalAutoProxyCreator,personService,simpleAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in file [E:\java\sts-workspace\spring-aop-aspect\target\classes\cn\outofmemory\spring_aop_aspect\PersonService.class]: Initialization of bean failed; 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.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at cn.outofmemory.spring_aop_aspect.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:104)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:476)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    ... 11 more

从字面意思看是缺少cglib包的引用,解决此问题的方法是下载cglib包或者在maven中添加cglib的依赖:

可以从 http://cglib.sourceforge.net/ 下载cglib包,或者在maven中添加如下依赖项:

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

标签:spring,aop,cglib

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. hellas 发表 2018-03-13 12:48:12 Spring AOP 实现读写分离
  2. yanxinchi 发表 2018-03-17 06:08:44 金三银四跳槽季,Java面试大纲
  3. ecnuys 发表 2016-02-18 12:07:05 跟我学Spring3(6.7): 通知顺序
  4. hellas 发表 2017-08-07 10:14:34 一起来学SpringCloud之 – 断路器Hystrix(Ribbon)
  5. 尖兵 发表 2017-08-14 11:20:51 Spring-SpringMVC父子容器&AOP使用总结
  6. xiaoli.he 发表 2018-01-07 13:56:26 初学 Spring Boot,你需要了解的 7 样东西
  7. 邓龙华 发表 2018-03-11 14:05:55 Spring入门看这一篇就够了
  8. changyuan.xu 发表 2018-03-13 11:22:40 一起来谈谈 Spring AOP!
  9. 博主 发表 2014-03-13 14:58:06 Spring AOP之入门实例
  10. 博主 发表 2014-03-13 14:58:06 Spring AOP之入门实例
  11. changyuan.xu 发表 2017-07-16 10:34:52 spring核心AOP(面向切面编程)总结
  12. 邓龙华 发表 2017-07-28 19:25:51 Spring框架中的设计模式(四)

发表评论