• Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Implemented
    • Affects Version/s: 6.18.0, 7.0.0-M4
    • Fix Version/s: 7.0.0-M5
    • Component/s: wicket-spring
    • Labels:
    • Environment:
      Spring Framework 4.1.4.RELEASE (currently the latest version)


      Short Description:
      Since Spring Framework 4.0, Spring is able to inject/autowire generic beans like:

      @Autowired public GenericDao<Car> genericCarDao;

      As is described here: .
      However, SpringBean doesn't seem to support this yet, resulting in a IllegalStateException.

      Detailed Description
      Given the following code:

      public interface GenericDao<T> {}
      public class CarDao implements GenericDao<Car> {}
      public class PhoneDao implements GenericDao<Phone> {}
      public class DaoClient {
          @Autowired public GenericDao<Car> genericCarDao;
          @Autowired public CarDao nonGenericCarDao;

      Spring 4 is able to inject both "genericCaoDao" and "nonGenericCarDao" into the DaoClient class.

      Performing the same using SpringBean, fails:

      public class HomePage extends WebPage {
      	@SpringBean private CarDao nonGenericCarDao;
      	@SpringBean private GenericDao<Car> genericCarDao;

      In this case, SpringBean is unable to inject "genericCarDao", and throws the following error:

      Caused by: java.lang.IllegalStateException: More than one bean of type [com.mycompany.springcomponents.GenericDao] found, you have to specify the name of the bean (@SpringBean(name="foo")) or (@Named("foo") if using @javax.inject classes) in order to resolve this conflict. Matched beans: carDao,phoneDao
      	at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanNameOfClass(
      	at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanName(
      	at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(
      	at org.apache.wicket.injection.Injector.inject(
      	at org.apache.wicket.spring.injection.annot.SpringComponentInjector.inject(
      	at org.apache.wicket.spring.injection.annot.SpringComponentInjector.onInstantiation(
      	at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(
      	at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(
      	at org.apache.wicket.util.listener.ListenerCollection.notify(
      	at org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(
      	at org.apache.wicket.Component.<init>(
      	at org.apache.wicket.MarkupContainer.<init>(
      	at org.apache.wicket.Page.<init>(
      	at org.apache.wicket.Page.<init>(
      	at org.apache.wicket.markup.html.WebPage.<init>(
      	at com.mycompany.HomePage.<init>(

      Workaround solution:
      Explicitly using bean names (qualifiers) does work. In this case

      @SpringBean private CarDao nonGenericCarDao;
      @SpringBean private GenericDao<Car> genericCarDao;

      has to be changed to:

      @SpringBean(name = "carDao") private CarDao nonGenericCarDao;
      @SpringBean(name = "carDao") private GenericDao<Car> genericCarDao;

      Description of some of the attached files:

      • pom.xml: added spring-context, spring-web, wicket-spring dependencies. Changed java version to 1.8.
      • WicketApplication: added Spring support
      • SpringApp: boots plain Spring and shows that DaoClient is able to autowire generic beans.
      • HomePage: a Wicket WebPage that shows that SpringBean throws the error when using generic beans.


          9 kB
          Tobias Soloschenko
          8 kB
          Tobias Soloschenko
          13 kB
          Flying Wolf
          2 kB
          Tobias Soloschenko
          10 kB
          Tobias Soloschenko
          10 kB
          Tobias Soloschenko

          Issue Links



              • Assignee:
                bitstorm Andrea Del Bene
                flyingwolf Flying Wolf
              • Votes:
                0 Vote for this issue
                5 Start watching this issue


                • Created: