java - Wicket @SpringBean and Spring @Autowired with injection via constructor -


i have wicket panel in want inject bean using @springbean

public class somepanel extends panel {    @springbean   private blogsummarymailgenerator blogsummarymailgenerator;  } 

but blogsummarymailgenerator has injection via constructor defined this:

@component public class blogsummarymailgenerator {    private blogrepository blogrepository;   private blogpostrepository blogpostrepository;    @autowired   public blogsummarymailgenerator(blogrepository blogrepository,                                 blogpostrepository blogpostrepository) {     this.blogrepository = blogrepository;     this.blogpostrepository = blogpostrepository;   } } 

and when somepanel instantiated getting exception

caused by: java.lang.illegalargumentexception: superclass has no null constructors no arguments given @ net.sf.cglib.proxy.enhancer.emitconstructors(enhancer.java:721) ~[cglib-3.1.jar:na] @ net.sf.cglib.proxy.enhancer.generateclass(enhancer.java:499) ~[cglib-3.1.jar:na] @ net.sf.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25) ~[cglib-3.1.jar:na] @ net.sf.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:216) ~[cglib-3.1.jar:na] @ net.sf.cglib.proxy.enhancer.createhelper(enhancer.java:377) ~[cglib-3.1.jar:na] @ net.sf.cglib.proxy.enhancer.create(enhancer.java:285) ~[cglib-3.1.jar:na] @ org.apache.wicket.proxy.lazyinitproxyfactory.createproxy(lazyinitproxyfactory.java:191) ~[wicket-ioc-7.2.0.jar:7.2.0] 

adding empty no-args constructor blogsummarymailgenerator solves issue adding such code make injection work wrong , avoid it.

any suggestions how make @springbean work beans using injection via constructor?

solution

to able take advantage of constructor injection @springbean in wicket components have add objenesis compile time dependencies.

explanation

objenesis little , less known byte code manipulation library (in opposite cglib provided wicket) able create proxy object class has no default (no args) constructor. if add compile dependency project wicket switch it's internal lazily initializable proxy creation logic take advantage of objenesis (instead cglib requires no args constructor) while instantiating proxy. unfortunately feature not documented can confirm works in case.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -