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

Reference to mongoTemplate (MongoDB), entityManagerFactoryRef (JPA),.. in @Repository

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.11.2 (Gosling SR2)
    • Fix Version/s: None
    • Component/s: Repositories
    • Environment:
      Spring Data

      Description

      With @Repository we have a comfortable solution to declare a Spring Data Repository as a bean (via component scanning). For projects having a single mongoTemplate for example this works quite well. When we have multiple mongoTemplates in a project there is no other way than declaring the base packages in an additional @Configuration, like this:

      MongoConfig.java
      @Configuration
      @EnableMongoRepositories(
          basePackages   = "org.foo.bar.domain1",
          mongoTemplateRef = "myMongoTemplate"
      )
      

      When we create another repository in org.foo.bar.domain2, we have to add this base package to the component scan. In a more complex project the amount of @Configuration classes for DB configurations is rapidly growing sometimes.

      I found it intuitive to declare a reference to a mongoTemplate (only speaking for MongoDB for now, should work for JPA,... as well) in the @Repository annotation. As a possible solution a @MongoRepository (extending @Repository) could be introduced - having an attribute mongoTemplate. With this method we could avoid adding new base packages to the component scan manually and reduce the amount of @Configuration classes.

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            alwi All Wissender
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: