Search code examples
javaspringspring-datacouchbasespring-data-couchbase

Redefine methods in repository with spring-data


I'm using spring-data-couchbase 2.1.2, I want add methods to a single repository. In implementation class:

public class MyRepositoryImpl implements MyRepositoryCustom { 

  @Autowired
  RepositoryOperationsMapping templateProvider; 
....
}

I added the RepositoryOperationsMapping but the object is not injected, I have the error below:

[org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException

For spring configuration I used the spring.xml file, how add in xml file the RepositoryOperationsMapping reference?

Thanks. Bye.


Solution

  • I solved the issue, below a snippet my spring.xml file

    <couchbase:clusterInfo login="${cluster.username}" password="${cluster.password}"  id="clusterInfo" />
    
        <couchbase:bucket bucketName="${bucket.name}" bucketPassword="${bucket.password}" id="bucket"/>
    
        <!-- template is just using default parameters and references as well -->
         <couchbase:template translation-service-ref="myCustomTranslationService" />
         <bean id="myCustomTranslationService" 
      class="org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService"/>
    
    
    
       <bean id="couchbaseTemplate" class="org.springframework.data.couchbase.core.CouchbaseTemplate">
            <constructor-arg ref="clusterInfo"/>
            <constructor-arg ref="bucket" />
            <constructor-arg ref="myCustomTranslationService" />
       </bean> 
    
       <bean id="repositoryOperationsMapping" class="org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping"> 
         <constructor-arg ref="couchbaseTemplate"/> 
       </bean>