Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create proxy for spring component without default constructor #232

Closed
i-dorofeev opened this issue Apr 3, 2018 · 2 comments
Closed

Comments

@i-dorofeev
Copy link

I receive an error when trying to obtain a bean which class doesn't have a default constructor (has its constructor arguments autowired) from ApplicationContext:

Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given                                                                                                          
  at org.springframework.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:931)                
  at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:631)                   
  at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)                                                                                                                 
  at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)                                                                                                                    
  at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492)                        
  at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)                                                                                                      
  at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)                                                                                                      
  at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)           
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)                                    
  at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)      
  at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)              
  at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)                                                                                                         
  at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)                                                                                                                      
  at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)                    
  at org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:305)                          
  at HotswapAgentSpringBeanProxy_1796692748.create(HotswapAgentSpringBeanProxy_1796692748.java)  
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                 
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)               
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       
  at java.lang.reflect.Method.invoke(Method.java:498)                                            
  at org.hotswap.agent.plugin.spring.getbean.EnhancerProxyCreater.create(EnhancerProxyCreater.java:87)                                                                                                                  
  at org.hotswap.agent.plugin.spring.getbean.EnhancerProxyCreater.createProxy(EnhancerProxyCreater.java:78)                                                                                                             
  at org.hotswap.agent.plugin.spring.getbean.ProxyReplacer.register(ProxyReplacer.java:59)       
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:374)                                                                                                  
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:334)                                                                                                  
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1088)       
@gallyamb
Copy link

+1

@edudant
Copy link
Contributor

edudant commented May 7, 2018

Proxy of a class without default constructor is supported from Spring4:
// Spring 4: CGLIB-based proxy classes no longer require a default constructor. Support is provided
// via the objenesis library which is repackaged inline and distributed as part of the Spring Framework.
// With this strategy, no constructor at all is being invoked for proxy instances anymore.

For more explanation see http://blog.codeleak.pl/2014/07/spring-4-cglib-based-proxy-classes-with-no-default-ctor.html.

I have replicated Spring solution with Objenesis library.

@edudant edudant closed this as completed May 7, 2018
edudant pushed a commit that referenced this issue May 16, 2018
… cglib version and cache problem. Proxy of class without default constructor NOT supported for theses versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants