Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-893

Allow setting a qualifier for the generated repository beans

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Waiting for Feedback
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.12.2 (Hopper SR2)
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:

      Description

      If I want to have a custom repository implementation, besides the one generated, I can add a qualifier to it.

      @Qualifier("LDAP")
      public class LdapPersonsRepository implements PersonsRepository {
      }
      
      <jpa:repositories base-package="org.example" />
      
      public class PersonsFacadeImpl implements PersonsFacade {
      	@Autowired
      	private PersonsRepository personsRepository;
      
      	@Autowired
      	@Qualifier("LDAP")
      	private PersonsRepository ldapPersonsRepository;
      }
      

      But then I discover that there's another PersonsRepository already defined in another package.
      I discover that I can name this repository:

      @Component("siteAccess.personsRepository") // name it to avoid conflicts
      public interface PersonsRepository extends Repository<Person, String> {
      }
      

      But then PersonsFacadeImpl#personsRepository doesn't get injected anymore, so I have to updated it:

      public class PersonsFacadeImpl implements PersonsFacade {
      	@Autowired
      	@Qualifier("siteAccess.personsRepository")
      	private PersonsRepository personsRepository;
      
      	@Autowired
      	@Qualifier("LDAP")
      	private PersonsRepository ldapPersonsRepository;
      }
      

      I think it would be nicer to be able to set a qualifier for the generated repositories, like

      <jpa:repositories base-package="org.example" qualifier="JPA" />
      

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            shadow Andrei Ivanov
            Last updater:
            Mark Paluch
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: