Results 1 to 2 of 2

Thread: mongo-template-ref in repository element?

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Default mongo-template-ref in repository element?

    Hi,

    I'm using version 3.1.2.RELEASE of Spring.

    I would like to be able to specify the template bean that backs my repository bean, using the Spring MongoDB data library.

    http://michaelbarnesjr.wordpress.com...ng-data-mongo/ seems to suggest that you may have a mongo-template-ref parameter as an attribute of a repository element (nested inside of a repositories element) in the application context xml. However, when I try this, I get an exception when trying to instantiate the bean saying that the "mongoTemplate" bean cannot be found-- even though I actually specified a different MongoTemplate bean to use.

    In case it is relevant, my MongoTemplate bean is specified in terms of a FactoryBean.

    I notice that if I have the mongo-template-ref attribute in the repositories element instead, then things seem to work, but this won't be as convenient when I have more than one repository.

    My MongoTemplate bean is specified as:
    Code:
    <bean id="jobMongoTemplate"
          class="[...].MongoOperationsFactoryBean">
        <constructor-arg name="mongoManager" ref="developmentMongoManager" />
        <constructor-arg name="dbName" value="Jobs" />
      </bean>
    My repositories element, with the mongo-template-ref attribute on the repository element is:
    Code:
      <mongo:repositories base-package="[...].repositories">
        <mongo:repository id="jobRepository" mongo-template-ref="mongoTemplate"/>
      </mongo:repositories>
    JobRepository is the only interface that exists in the specified repositories package.


    Can the mongo-template-ref attribute in fact be used in the repository element... or does it only work in the repositories element? Is there a possible complication from using a FactoryBean to produce the MongoTemplate bean?

    Thank you.

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    The <repository /> element was removed in Spring Data MongoDB 1.2.0. The workaround is to use two <repositories /> elements with dedicated include/exclude filters and set the mongo-template-ref attribute on the repositories element.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •