Search code examples
springmongodbspring-dataspring-mongo

Mongo custom repository naming problems


I have definitions:

public interface  FruitsRepository extends MongoRepository<Fruits, String>,  FruitsRepositoryCustom {
...
}

public interface  FruitsRepositoryCustom {
...
}

public class FruitsRepositoryImpl implements  FruitsRepositoryCustom {
...
}

When I try to change the name of FruitsRepositoryImpl to FruitsRepositoryXImpl it is no recognized by spring and I am getting exception. What is the cause of this and how can I change the name of class that implements by custom interface?


Solution

  • The custom repository implementation name postfix is Impl by default.

    In order to change it to XImpl you should change the repository-impl-postfix attribute of the repositories element. Something such as:

    <repositories repository-impl-postfix="XImpl" base-package=...>

    Or by using Java:

    @EnableMongoRepositories(repositoryImplementationPostfix="Ximpl" basePackages=...)

    However, note that changing the postfix name applies to all custom repositories.

    See more at the reference documentation, namespace reference