On Tue, Apr 4, 2017 at 9:40 PM, Tomasz Dziurko <[email protected]> wrote:
> Hi Martin > > Two questions: > 1. Which class? HomePageHandler ? > Yes, HomePageHandler. The problem is the following: @SpringBean tell Wicket to inject a proxy in the Wicket components. If the class is an interface then Wicket uses java.lang.reflect.Proxy and all is fine. If it is a proper class then Wicket uses CGLIB to create the proxy. CGLIB requires a default constructor to be able to create the specialization class. > 2. I have digged deeper and in fact there is a check whether to use CGLib > or Objenesis (if there is no-args constructor Objenesis is chosen) but is > Objenesis is a bit smarter than CGLIB. It looks for the available constructors and creates proxies for the parameters to be able to instantiate the class (HomePageHandler). Wicket uses CGLIB since day 1 of wicket-inject module. Objenesis fallback has been added recently (1-2 years ago) so that people can "migrate" from CGLIB to the more powerful Objenesis if they want by excluding CGLIB from the classpath and adding Objenesis. Few months ago there was a discussion at dev@ to replace CGLIB with ByteBuddy (the most powerful and maintained proxy creation library at the moment) but we decided that it is not worth the troubles yet. > it an expected behaviour? Or maybe this case could be a trigger to discuss > proper way to deal with such cases? > > On 4 April 2017 at 21:26, Martin Grigorov <[email protected]> > wrote: > > > Hi, > > > > On Apr 4, 2017 7:38 PM, "Tomasz Dziurko" <[email protected]> wrote: > > > > Hello > > > > I have a problem with wicket-spring-boot <-> wicket integration. Bean > > annotated with @Serviceis not properly injected into a backing bean that > is > > injected into a stateless Page using @SpringBean annotation. > > > > Generally: > > > > @StatelessComponent > > @MountPath("home-page") > > public class HomePage extends WebPage { > > > > @SpringBean > > private HomePageHandler handler; > > } > > > > and > > > > @Service > > public class HomePageHandler { > > > > private final CommandPublisher commandPublisher; > > > > @Autowired > > public HomePageHandler( > > > > > > I think you will need an additional default constructor for this class. > > CGLIB needs it. > > It might have lesser visibility than public too. > > > > CommandPublisher commandPublisher) { > > this.commandPublisher = commandPublisher; > > } > > > > public void executeAction(String name) { > > commandPublisher.publish(name); /// <----------- NPE > > (commandPublisher is null) > > } > > } > > > > and: > > > > @Service > > public class CommandPublisher { > > > > public void publish(String text) { > > eventPublisher.publishEvent(text); > > } > > > > } > > > > Wicket 7.6.0, wicket-spring-boot 1.0.6. > > > > I have created a simple starter ( > > https://github.com/tdziurko/wicket-spring-bean-issue) to reproduce the > > problem. Problem disappears when page is not stateless (more info in > readme > > in the starter). > > > > > > Thank you in advance for help. > > > > -- > > Regards / Pozdrawiam, > > Tomek Dziurko > > http://tomaszdziurko.com/ > > > > > > -- > Regards / Pozdrawiam, > Tomek Dziurko > http://tomaszdziurko.com/ >
