Could not initialize class net.sf.cglib.proxy.Enhancer
Asked Answered
D

5

10

Getting the following error when trying to run a spring mvc application with hibernate in eclipse.

java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib2AopProxy.java:229)
org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:171)
org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:112)
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:476)
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:551)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:679)

I've placed cglib-nodep-2.2.3 .jar into my web-inf/lib folder but I'm continuing to get the same error. Not sure why as the class is there in the jar. I get the same error message whether or not the jar is there.

Dunc answered 20/9, 2012 at 9:16 Comment(0)
S
17

This problem is caused by not including the asm dependencies that cglib has.

Solution 1: Add the correct versions of asm and asm-util to your classpath

Solution 2: Use the cglib-nodep version (which includes both asm dependencies).

Shantel answered 22/11, 2012 at 13:17 Comment(1)
I can't thank you enough for your valuable answer for the problem. I was facing the same issue and tried many different ways to fix the problem. Nothing worked except adding asm dependency to project. Here is my question link - https://mcmap.net/q/1176750/-apache-wicket-java-lang-noclassdeffounderror-could-not-initialize-class-net-sf-cglib-proxy-enhancer/819866 Thanks again.Vientiane
F
4

Ok as there is no solution and I have faced the same problem and I have fixed it so i am putting my solution here..

The

Could not initialize class net.sf.cglib.proxy.Enhancer

is related to cglib-nodep jar as told by @swemon

So even after downloading the latest one and adding to my build path it didnt worked because previously I had an older version which was still there in JBOSS/deploy/server/myServer/lib folder. All i did is replaced the required jar(cglib-nodep.jar with cglib-nodep-2.2.jar) in this folder, did a buid, restarted the server and done.

NB: Your version for cglib-nodep jar can be different from mine. Make sure to use the right version of Jar. NB:2: Your deploy folder of your server can be different from mine based on what app server you are using..

Hope that helps!

Familiarity answered 17/10, 2012 at 12:43 Comment(0)
A
1

You are missing jar. I think cglib-nodep-2.2.3.jar does not include the class net.sf.cglib.proxy.Enhancer you need. You should try http://www.jarfinder.com/index.php/java/search/~net.sf.cglib.proxy.Enhancer~ to find which jar file include this class and add one of these jar file to build path.

If you find your class is contained in which jar, after you adding your lib to web-inf/lib folder,

  • Right click on your project
  • Click Build Path > Configure Build Path...
  • Choose Libraries tag and click Add JARs...
  • Point your jar and click OK.
  • Rebuild and run again.
Awe answered 20/9, 2012 at 9:20 Comment(4)
That's the thing, it DOES include the class. I can quite clearly see it when I expand the jar in the Project Explorer window.Dunc
Do you mean the class file is already included in jar file?? And Still NoClassDefFoundError found??Awe
Yes, that's right. The class file in there within the jar but it continues to give the same error message as it did when the jar is not there.Dunc
I added the jar as an external jar to the build path but this has made no difference. I still receive the same error.Dunc
U
0

After long long debug, i got the solution. Just need to change the aop:config along with the properly added jars as stated above,

aop:config proxy-target-class="true"

Chaitanya !

Unguarded answered 4/6, 2013 at 12:8 Comment(0)
A
0

Try including this as jvm option: --add-opens java.base/java.lang=ALL-UNNAMED

Anthropophagite answered 15/1 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.