Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2781

Support @SpringBean injection into generic superclass

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 1.4.7
    • None
    • wicket-spring
    • None

    Description

      It's possible to inject Spring Beans into a generic superclass, if the field type to be injected is a type variable. I will attach a patch that does this (I don't know if it's the best or most general implementation, but it works in my case). This allows us to reduce code in a wicket-spring project and it would be great if you could integrate this change into wicket-spring.

      This also allows better integration with Scala because it seems Scala initialization order is different enough from Java that it seems impossible to make a variable injected into a subclass of a generic superclass available to the generic superclass's constructor.

      Simplified example for the motivation:

      public abstract class EditPage<EntityType, RepoType extends IRepository<EntityType>> {
      @SpringBean
      RepoType repository;
      ...
      }

      Concrete "edit pages" extend this and define EntityType and RepoType. Injecting in the superclass allows the subclasses to be very thin, which is great. I was not able to implement this in Scala (maybe there's some trick but I don't know), even if I replace the repostiory with: protected abstract RepoType getRepository() and implement this in a Scala subclass:
      class UserEditPage extends EditPage<User, UserRepo> {
      @SpringBean
      var repo: UserRepo = _
      def getRepository = repo
      }
      when the superclass' constructor calls getRepository, it will get null (and sometimes method not found getRepository: IRepository, but that might be due to JRebel)

      Attachments

        1. wicket-spring-inject-patch.txt
          4 kB
          Erkki Lindpere

        Activity

          People

            ivaynberg Igor Vaynberg
            villane Erkki Lindpere
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: