There was an error in this gadget

Friday, October 14, 2011

java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given

Trying to deploy a Spring/Hibernate and hitting the wall with this ??


Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given

at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721) [:]

at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499) [:]
at net.sf.cglib.transform.TransformingClassGenerator.generateClass (TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate (DefaultGeneratorStrategy.java:25) [:]
at net.sf.cglib.core.AbstractClassGenerator.create (AbstractClassGenerator.java:216) [:]
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) [:]
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) [:]
at org.springframework.aop.framework.Cglib2AopProxy.getProxy 
(Cglib2AopProxy.java:200) [:3.0.5.RELEASE]




Or something like


org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.simplepersoncrud.application.services.PersonService]: 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
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) [:3.0.5.RELEASE]

.........


I have hit the wall with this exception while I was working on


Solution:

Do you have a spring bean which is annotated with @Transactional ? or have you configured it to transactional through a spring config ?

Do you have any spring bean which is going to use AOP in any form ?

Have you configured your application to use CGLib to assist you with proxy generation which is required in case of AOP ?

If you answer Yes to all the above questions then read on, if you answer No to any of the questions then it is unlikely that you will find a solution for your problem here…


Solution : For the beans that have been configured to be surrounded with AOP proxies check if you have a default constructor !!

My bet is you do not have a default constructor

You probably have defined a custom constructor and then missed out on defining a default no arg constructor.

Define default constructors for all such AOP decorated beans.

Redeploy your application and it should work !!

If you do not want to use CGLib or similar byte code manipulation libraries have a look at JDK Dynamic Proxies for spring



If you still cannot climb over the wall,post your problem as comment, I will be more than happy to help :)


3 comments:

  1. Replies
    1. I must thank you the very first comment and that too a good one :)

      Delete
  2. Or use AspectJ instead of proxies. Have a look at the commment by Craig Walls in: http://stackoverflow.com/questions/15223297/spring-social-superclass-has-no-null-constructors-but-no-arguments-were-given

    ReplyDelete