Dogukan Sonmez

Currently in Munich, Germany

Java Groovy Python

No-Sql TDD Scrum

Django Shell Cloud

May 09 2012

Cannot proxy target class because CGLIB2 is not available

While working with spring AOP I got this error after transporting repository from svn to git. Most probably you got this error because of two reasons.

  • You don't have cglib lib in your classpath or your maven dependency pom
  • You are proxying a class not interface

Since there are two reason I have two solutions. For those who don't want proxiying an interface should add cglib to dependency of project. If you are using maven it's quite simple as blow.

    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2</version>
    </dependency>
     

For those who don't like to add cglib need to implement an interface for proxying class. Below you can find a snapshot of exception trace.

        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:65)
        at org.springframework.aop.framework.ProxyCreatorSupport.
		createAopProxy(ProxyCreatorSupport.java:106)
        at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:97)
        at org.springmodules.cache.interceptor.proxy.
		CacheProxyFactoryBean.afterPropertiesSet(CacheProxyFactoryBean.java:125)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
		nvokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
		initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
		createBean(AbstractAutowireCapableBeanFactory.java:425)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.
		getObject(AbstractBeanFactory.java:251)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.
		getSingleton(DefaultSingletonBeanRegistry.java:156)
        at org.springframework.beans.factory.support.AbstractBeanFactory.
		getBean(AbstractBeanFactory.java:248)
		...
      

For more information visit spring aop